当尝试创建本地local数据库链接时总是提示如下的错误
Your connection attempt failed for user 'root' from your host to server at 0.0.0.0:3306:
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
Please:
1 Check that mysql is running on server 0.0.0.0
2 Check that mysql is running on port 3306 (note: 3306 is the default, but this can be changed)
3 Check the root has rights to connect to 0.0.0.0 from your address (mysql rights define what clients can connect to the server and from which machines)
4 Make sure you are both providing a password if needed and using the correct password for 0.0.0.0 connecting from the host address you're connecting from
后来尝试修改root的默认密码,成功了,具体步骤如下:
1、首先关闭mysql服务器
可以直接在系统偏好里有个MySQL里关闭。
2、cd /usr/local/mysql/bin 进入mysql的目录
3、sudo su 获取权限
4、./mysqld_safe --skip-grant-tables & 重启服务器(&千万别漏掉,我第一次失败的原因是copy的时候复制遗漏了)
重启完之后,可以在系统偏好中看到mysql已经启动了。
5、重新开个终端,配置短命令:
alias mysql=/usr/local/mysql/bin/mysql (这一步可以不执行,不过之后的mysql就要用全称了)
6、输入mysql 进入mysql命令模式
7、use mysql进入mysql数据库
8、flush privileges 获取权限,要不他不让你改。
9、SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码'); 完成修改
10、exit退出之后,就可以用新密码登陆了
上面这一步SET PASSWORD FOR 'root'@'localhost' = PASSWORD('你的新密码'); 完成修改设置密码怎么设置都不成功,总提示语法错误,因此又查看了其他的修改方式,最终版本如下:
mysql> update mysql.user set authentication_string =password('你的新密码') where User='root';