linux - mysql - 忘记用户名、密码

1, 关闭mysql服务

/etc/rc.d/init.d/mysqld stop


2,使用 –skip-grant-tables选项启动mysql服务

(1)打开文件 mysqld

vi /etc/rc.d/init.d/mysqld

(2)编辑文件 mysqld,在下面运行启动的语句里增加--skip-grant-tables

/usr/bin/mysqld_safe --skip-grant-tables --datadir="$datadir" --socket="$socketfile"

--log-error="$errlogfile" --pid-file="$mypidfile"

加入--skip-grant-tables的意思是启动mysql服务的时候跳 过权限表认证。启动后,连接到mysql的root不需要口令

 

3,重新启动mysql服务

/etc/rc.d/init.d/mysqld start

 

4,登录mysql

 mysql -u root -h 127.0.0.1 -P3306 -p

备注:直接回车进入就好,此时不输入密码也可以登录mysql

 

5,修改root用户的密码

mysql> select host,user,password from mysql.user;

mysql> update mysql.user set password=password('1111') where user='root';

mysql> flush privileges;

mysql> quit


5, 重新启动mysql,就可以使用 新密码登录了

/etc/rc.d/init.d/mysqld restart   //重新启动mysql

mysql -u root -h 127.0.0.1 -P3306 -p

输入密码:123456

posted @ 2018-11-13 15:04  萧韶九成  阅读(7793)  评论(0编辑  收藏  举报