1、use mysql;(切换到mysql数据库下)
2、select user,host from user;(查看是否又root用户,如果没有,则需要创建)
3、grant select,insert,update,delete on *.* to root@"%" identified by "root";(增加新用户。格式:grant select on 数据库.* to 用户名@登录主机 identified by “密码”)
4、ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root';
5、flush privileges;(刷新权限,是命令生效)
6、exit;
7、把/etc/my.cnf中的"skip-grant-tables"删掉
8、重启数据库(service mysql restart)
9、mysql -uroot -p 测试密码是否修改成功
注意:ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement,需先flush privileges;刷新权限。
1、首先找到my.cnf ,一般在/etc/my.cnfvim /etc/my.cnf2、在[mysqld]下添加"skip-grant-tables",跳过密码验证3、重新启动数据库(service mysql restart)4、输入命令:mysql -u用户名 -p5、直接回车进入mysql命令行终端,use mysql;进入mysql数据库6、进入MySQL后,执行以下命令:1、use mysql;(切换到mysql数据库下)2、select user,host from user