CentOS 下 MySQL root 密碼重設

來源:互聯網
上載者:User

CentOS 下 MySQL root 密碼重設

CentOS 下 重設MySQL密碼的方法有很多,官網也提供了很方便的快捷操作辦法,可參考資料 resetting permissions 。本文重設密碼的具體步驟如下:

一、停止MySQL(如果處於運行狀態)

#service mysqld stop

輸出

Shutting down MySQL.                                      [  OK  ]

關於 #service mysqld stop 命令,可參考 CentOS 6.5 平台離線編譯安裝 MySQL 5.6.22。

二、啟動MySQL_safe,如此以來便可不用密碼登入MySQL

# mysqld_safe --skip-grant-tables &

輸出類似

Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

三、登入MYSQL

# mysql -u root

輸出

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

四、設定新密碼

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

五、停止MySQL

# /etc/init.d/mysql stop

輸出

Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/mysqld.pid
mysqld_safe[6186]: ended
[1]+  Done                    mysqld_safe --skip-grant-tables

六、啟動MySQL並測試新密碼是否正確

# /etc/init.d/mysql start
# mysql -u root -p

CentOS 6.4下安裝MySQL後重設root密碼方法

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.