一。停止mysql,修改配置文件,跳过密码验证登录:
# systemctl stop mysqld
# vim /etc/my.cnf
后面任意添加
# skip-grant-tables
启动mysql
# systemctl start mysqld
二。登录mysql
登录,直接输入mysql命令即可:
# mysql
修改密码:
#update user set password=password(‘123456’) where user = ‘root’;
如果报错:
ERROR 1054 (42S22): Unknown column ‘password’ in 'field list’
修改密码语句改为:
# update mysql.user set authentication_string=password(“root”) where user=“root” ;
刷新:
# flush privileges;
退出:
# exit;
三。重启mysql(非必须)
# systemctl restart mysqld