mac系统中mysql登录报错:Access denied for user 'root'@'localhost' (using password: NO)
1、关闭MySQL
sudo /usr/local/mysql/support-files/mysql.server start 启动
sudo /usr/local/mysql/support-files/mysql.server stop 关闭
sudo /usr/local/mysql/support-files/mysql.server restart 重启
2、在终端中以管理员权限启动mysqld_safe,命令如下:
cd /usr/local/mysql/bin
sudo su
./mysqld_safe --skip-grant-tables
3、不要关闭当前的终端窗口,新建一个终端窗口(command+n),输入如下命令,回车登录mysql
/usr/local/mysql/bin/mysql
4、重置密码
MySQL 8.0以下
set password for 'root'@'localhost'=password("1234");
MySQL 8.0以上
alter user 'root'@'localhost' identified by '1234';
5、刷新并退出。
flush privileges;
quit;