天天看點

騰訊雲mysql預設密碼,Linux系統下mysql忘記密碼解決方案_CentOS_初始密碼_騰訊雲

租了一台xx雲的雲主機伺服器,因為不想自己再安裝基礎環境了,于是就在他們應用市場裡購買了一套已經安裝好的Apache+Mysql+PHP的運作環境,進行系統重裝。

但是,但是...坑的是,重裝完沒給Mysql的初始密碼啊。。

以下是詳細修改密碼步驟:

第一步、 登入伺服器,找到 my.cnf 檔案,通常該檔案路徑為 /etc/my.cnf ,如果不在,可以用 find / -name my.cnf 指令查找一下。

**第二步、 ** 編輯 my.cnf 檔案 ,在[mysqld]下面加上 skip-grant-tables。

這句話會讓mysql資料庫登入時跳過密碼驗證,也就是說,root登入時,輸入什麼密碼都能進入資料庫管理。

【示例】

[mysqld]

skip-grant-tables

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

第三步、 重新開機mysql,指令:service mysqld restart

【回報】

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]

** 第四步、** 任意密碼登入mysql資料庫,使用指令:use mysql; 打開mysql資料庫。

【回報】

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection id is 3 to server version: 3.23.56

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

第五步、 使用指令:select user,host,password from user; 查詢資料庫使用者資訊,可以看到使用者名和對應的被加密後的密碼。

第六步、 使用指令:UPDATE user SET Password = password ( '你要修改的密碼' ) WHERE User = 'root' ; 為root修改為你要的新密碼。

【回報】

Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0

第七步、 退出mysql,指令:quit;

【回報】

mysql> quit

Bye

第八步、 vi編輯 my.cnf 檔案,将第二步添加的 skip-grant-tables 删除,或在前面加上#進行注釋。

第九步、 重新開機mysql,指令:service mysqld restart

【回報】

# /etc/init.d/mysqld restart

Stopping MySQL: [ OK ]

Starting MySQL: [ OK ]