1、检查mysql启动状况
# ps -ef | grep -i mysql
2、停止mysql服务
# service mysql stop
3、修改mysql的配置文件my.cnf
# vim /etc/my.cnf
//在配置文件中,增加2行代码
[mysqld]
skip-grant-tables
4、启用mysql服务
# service mysqld start
5、修改密码
# mysql -u root
//进入mysql库
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
//修改数据库用户密码
mysql> update mysql.user set authentication_string= password('root_password') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
//刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
6、重启mysql服务,使用新密码登录即可
service mysql start