網頁

搜尋此網誌

2014年10月4日 星期六

重設mysql root 密碼的方法:

忘記mysql root 密碼時可依下列方式修改:

[root@zabbix domo]# service mysqld stop  //停止mysql 
141004 20:20:55 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
正在停止 mysqld:                                          [  確定  ]
[root@zabbix domo]# mysqld_safe --skip-grant-tables &  //用此指令進入安全模式跳過檢查權限的資料表
[1] 3154
[root@zabbix domo]# 141004 20:21:33 mysqld_safe Logging to '/var/log/mysqld.log'.
141004 20:21:33 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

[root@zabbix domo]# mysql -u root  // 可用空密碼進入mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> update mysql.user set password=PASSWORD("mysql") where User='root';    //用此指令修改 root 密碼為mysql
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

mysql>  flush privileges;  //刷新MySQL的系統許可權
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@zabbix domo]# service mysqld start
正在啟動 mysqld:                                          [  確定  ]

可成功使用新密碼登入mysql
-----------------------------------------------------------
[root@zabbix domo]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.01 sec)

mysql>

沒有留言:

張貼留言