最近实验室内部的mysql的root密码被修改了,需要想办法修改新密码。方法如下:
1, 关闭mysql服务
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->/etc/init.d/mysqldstop
2,使用–skip-grant-tables选项启动MySQL服务,可以修改/etc/inin.d/mysqld脚本启动位置增加此选项,
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->vi/etc/init.d/mysqld
在下面运行启动的语句里增加--skip-grant-tables
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->/usr/bin/mysqld_safe--skip-grant-tables--datadir="$datadir"--socket="$socketfile"/
--log-error="$errlogfile"--pid-file="$mypidfile"/
--log-error="$errlogfile"--pid-file="$mypidfile"/
加入--skip-grant-tables的意思是启动MySQL服务的时候跳过权限表认证。启动后,连接到MySQL的root不需要口令
3,重新启动mysql服务
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->/etc/init.d/mysqldstart
4. 修改root用户的密码;
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->mysql>updatemysql.usersetpassword=PASSWORD('123456')whereUser=root;
mysql>flushprivileges;
mysql>quit
mysql>flushprivileges;
mysql>quit
5. 重新启动MySQL,就可以使用新密码登录了。
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->mysql-uroot–p
输入密码:123456
输入密码:123456
6,关闭mysql服务
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->/etc/init.d/mysqldstop
72/etc/init.d/mysqld--skip-grant-tables
8,mysql
<!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />-->/etc/init.d/mysqldstart