一、以系统的root用户登陆系统,进入终端
[root@localhost /]#
二、杀掉mysql进程
方法1、[root@localhost /]#killall mysqld
方法2、[root@localhost /]#ps -aux //查看所有进程,找到mysql进程的pid
然后
[root@localhost /]#kill pid //pid是mysql的进程号
三、用--skip-grant-tables参数启动mysqld
[root@localhost /]#/usr/local/mysql/bin/mysqld_safe --skip-grant-tables&
// 其中/usr..../bin是我的mysql安装目录
[root@localhost /]#/usr/local/mysql/bin/mysql //进入mysql
mysql> use mysql //切换到mysql database
mysql> UPDATE user SET password=password('123456') WHERE user='root';
//将root密码该为123456了
附:操作过程
[root@cat bin]# ./mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
1、杀掉mysql进程
[root@cat /]#killall mysqld
2、用--skip-grant-tables参数启动mysqld
[root@cat /]#/usr/local/mysql/bin/mysqld_safe --user=mysql --skip-grant-tables &
3、
[root@cat bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.
mysql> select * from mysql.user \G
*************************** 1. row ***************************
Host: localhost
User: root
Password: *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B
mysql> set password for 'root'@'localhost'=password(''); //改成相应密码
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
4、
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> set password for 'root'@'localhost'=password('');
Query OK, 0 rows affected (0.00 sec)
mysql> select * from mysql.user \G ;
*************************** 1. row ***************************
Host: localhost
User: root
Password: