今天在windows下用navicat连接虚拟机的mysql时,出现1045错误,如图:
在虚拟机的mysql目录下,用mysqld_safe --user=mysql命令启动数据库,再用mysql -uroot -p命令登录数据库,然后执行以下命令:
set password = ‘123456’;
grant all privileges on . to ‘root’@’%’ identified by ‘123456’;
grant all privileges on . to ‘root’@’%’ identified by ‘123456’ with grant option;
flush privileges;
SELECT * from mysql.user\G;
找到root用户的authentication_string这项,并把它的值记下来,然后继续执行以下命令:
update mysql.user set authentication_string = ‘*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9’ where user = ‘root’;here user = ‘root’;
flush privileges;
此时再次连接,连接成功。