1. 检查mysql服务是否启动,如果启动,关闭mysql服务
#检查mysql服务是否启动root@aly-hb5-ecs-001:~# ps -ef | grep -i mysqlmysql 18613 1 0 09:43 ? 00:00:01 /usr/sbin/mysqldroot 18904 18800 0 10:13 pts/0 00:00:00 grep --color=auto -i mysql#如果开着就运行关闭的命令root@aly-hb5-ecs-001:~# service mysql stop
2.修改mysql的配置文件my.conf
一般在/etc目录下,运行命令:vi /etc/my.cnf,编辑文件
在文件的[mysqld]标签下添加一句:skip-grant-tables
root@aly-hb5-ecs-001:~# vim /etc/mysql/mysql.conf.d/mysqld.cnf
[mysqld]
skip-grant-tables ##追加此行,跳过权限表
3.重启数据库
service mysql restart
4.进入到mysql数据库
mysql -u root
5.修改密码
use mysql;
update mysql.user set authentication_string=password('123456') where user='root';
update mysql.user set authentication_string=password('123456') where user='root' and Host ='%';
alter user user() identified by "123456";
flush privileges;
quit;
