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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM