1. 系统偏好设置无法关闭服务
停止服务:
sudo /usr/local/mysql/support-files/mysql.server stop
启动服务:
sudo /usr/local/MySQL/support-files/mysql.server start
重启服务:
sudo /usr/local/mysql/support-files/mysql.server restart
2. 终端连接报错ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
2.1 关闭mysql服务
2.2 进入终端
- 终端进入:
cd /usr/local/mysql/bin/
回车 - 登陆管理员权限:
sudo su
回车后输入管理员密码 - 输入以下命令来禁止mysql验证功能
./mysqld_safe --skip-grant-tables &
回车后mysql会自动重启(偏好设置中mysql的状态会变成running) - 输入命令以后
./mysql
回车 - 设置一个新的密码
SET PASSWORD FOR 'root@localhost'=(你的新密码) ;
(最后有一个分号)
此时会可能出现另外一个报错:ERROR 1290 (HY000):The MySQL server is running with the–skip-grant-tablesoption。输入下面命令
flush privileges;
然后再次输入命令修改密码,可能会再次出现问题:ERROR 1133 (42000): Can‘t find any matching row in the user table。执行下面命令
1. use mysql;
2. select Host,User from user;
那么需要增加用户的操作:
create user 'root'@'%' identified by '123456';
然后我们再来查询 mysql.user 的记录,可以发现有了 ‘root’@‘%’ 这条记录 :
然后更新权限:
flush privileges;
grant all privileges on *.* to 'root'@'%';
然后输入修改密码命令继续报错:corresponds to your MySQL server version for the right syntax to use near ‘password(‘123456’)’ at line 1
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘password(‘123456’)’ at line 1
接着执行下面命令:
查看mysql版本:select version();
接着执行:alter user 'root'@'localhost' identified by '123456';
mysql> alter user ‘root’@‘localhost’ identified by ‘123456’;
Query OK, 0 rows affected (0.01 sec)
-
重新打开一个终端进行测试:
-
输入exit