问题:远程连接linux系统mysql报错“Access denied for user ‘root’@‘localhost’ (using password: YES)” 解决方法:
编辑 /etc/my.cnf ,在[mysqld] 部分最后添加一行skip-grant-tables vim /etc/my.cnf
重启mysql service mysqld restart
免密进入mysql,提示输入密码时按enter键进入即可 mysql -uroot -p
重设密码,your_pwd就是你要设置的密码。 use mysql update user set password=password("your_pwd") where user='root'; 如有报错:Unknown column 'password' in 'field list'采用如下语句来更新,因为新版本mysql采用authentication_string替代了password字段 update mysql.user set authentication_string=password('your_pwd') where user='root' ;
刷新权限 flush privileges;
编辑/etc/my.cnf,删除第1步添加的那一行。
重启mysql,用第4步设置过的密码进入mysql。 service mysqld restart mysql -uroot -p
授权root用户远程连接:使用新密码进入mysql之后,执行以下命令 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'your_pwd' WITH GRANT OPTION;
FLUSH PRIVILEGES;
*.* 表示授权所有数据库的所有表权限your_pwd 表示远程连接的密码 可能报错:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.解决:先执行下面这一条命令,再执行上面那两条命令。 ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_pwd';如果执行ALTER命令出错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements,则需要修改mysql的密码策略,查看修改mysql的密码策略 使用navicat premium访问测试成功。