linux下如何修改Mysql的root密码

来源:互联网 发布:淘宝金币不够用怎么办 编辑:程序博客网 时间:2024/06/10 02:02

转载自http://blog.sina.com.cn/s/blog_538f130c01016svy.html

略有修改,把其精简了一下。


忘了mysql下的root密码,重置:

先关闭mysql:

root@ubuntu:/usr/local/mysql# ./support-files/mysql.server stop
Shutting down MySQL
.... * 

跳过授权表启动mysql,关闭网络监听,让其后台运行或者开个新终端。
root@ubuntu:/usr/local/mysql#mysqld_safe --skip-grant-tables --skip-networking
Starting mysqld daemon with databases from /var/lib/mysql

提示:此时按下CTRL-Z
[1]+  Stopped                 mysqld_safe --skip-grant-tables --skip-networking

root@ubuntu:/usr/local/mysql#bg
[1]+ mysqld_safe --skip-grant-tables --skip-networking &

3、链接mysql服务器。
root@ubuntu:/usr/local/mysql# ./bin/mysql //具体自己安装mysql地址,下面出现的不同版本有差异

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.19 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>

4、使用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>

5、设置root新密码。
mysql>update user set password=password('123') where user='root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
6、退出mysql。
mysql>quit
bye
 
7、重起mysql。 //不同版本有区别
root@ubuntu:/usr/local/mysql#./support-files/mysql.servermysqld restart
STOPPING server from pid file /var/run/mysqld/mysqld.pid
120928 11:38:28  mysqld ended
Stopping MySQL:                                            [  OK  ]
Starting MySQL:                                            [  OK  ]
[1]+  Done                    mysqld_safe --skip-grant-tables --skip-networking
现在你可以使用新的密码登录mysql了。

0 0
原创粉丝点击