天天看點

linux修改mysql配置檔案_linux下忘記mysql密碼後的修改。

linux修改mysql配置檔案_linux下忘記mysql密碼後的修改。

本來是風和日麗、陽光明媚的一天,然後開心的打開測試機搗鼓zabbix,突然一個mysql密碼錯誤擾亂了我的心緒。哎,好煩,要去修改mysql密碼了。

首先進入資料庫登入時密碼忘記,一直報錯:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

怎麼辦啊,試了好久,沒搞出來。

那麼就去修改mysql的配置檔案吧,切換root使用者,編輯/etc/my.cnf檔案。

在配置檔案裡面添加skip-grant-tables

linux修改mysql配置檔案_linux下忘記mysql密碼後的修改。

重新開機資料庫,使用無密碼登入。

[[email protected]]# mysql -uroot

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 1174

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

在mysql的指令行輸入:

update mysql.user set password=PASSWORD('新密碼')where User='root';

然後在mysql的指令行輸入:

flush privileges;

重新整理一下權限,并使用quit退出資料庫。

最後把/etc/my.cnf檔案中的skip-grant-tables删除掉,重新開機資料庫,使用新密碼登入。

[[email protected] ]# mysql -uroot -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 1174

Server version: 5.5.60-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

mysql的密碼修改成功了!

唯一的缺點就是需要重新開機mysql資料庫,是以大家還是一定要記住mysql的密碼!