目錄
背景
今天硬件測試在用平臺的時候說平臺掛了,開發人員檢查說環境被人修改了。無奈,測試站出來幫忙重新部署。
發現mysql進程在,說明有安裝mysql。試了密碼報錯,問了密碼大家都不知道。於是我想到了修改密碼。
看看報錯信息:
[root@zhangdi:~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
一、關閉mysql服務
service mysql stop
二、 修改mysql
的配置文件my.cnf
my.cnf
配置文件的位置,一般在/etc/my.cnf
,有些版本在/etc/mysql/my.cnf
在配置文件中,增加2行代碼
[mysqld]
skip-grant-tables
作用是登錄mysql
的時候跳過密碼驗證
然後啓動mysql
服務,並進入mysql
root@zhangdi:~# service mysql start
root@zhangdi:~#
root@zhangdi:~#
root@zhangdi:~# mysql -u root
三、修改密碼
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> update mysql.user set authentication_string=password('新密碼') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
四、重啓mysql服務
root@zhangdi:~# service mysql start
五、新密碼登陸成功
mysql -u root -p
Enter password:
root@zhangdi:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 5.7.30-0ubuntu0.18.04.1 (Ubuntu)
Copyright (c) 2000, 2020, 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.
修改完成
2020年5月20日。