一鍵部署
阿新 • • 發佈:2020-11-30
安裝MySQL
- Ubuntu:V18
參考:https://www.jianshu.com/p/4583aebf247a
sudo apt update
sudo apt install mysql-server
忘記mysql root密碼
參考:https://blog.csdn.net/luckytanggu/article/details/80251833
1、停止mysql服務
$ service mysql stop
2、修改my.cnf檔案
# 查詢my.cnf檔案在哪裡 $ find / -name my.cnf /var/lib/dpkg/alternatives/my.cnf /etc/alternatives/my.cnf /etc/mysql/my.cnf # 修改my.cnf檔案,在檔案新增 skip-grant-tables,在啟動mysql時不啟動grant-tables,授權表 $ vim /etc/mysql/my.cnf [mysqld] skip-grant-tables
3、啟動mysql服務
$ service mysql restart
4、更改mysql root使用者密碼
$ mysql # 選擇mysql資料庫 mysql> use mysql; # 更改user表中root使用者密碼 mysql> update user set authentication_string=PASSWORD("new_pass") where user='root'; # 注意:可能不同的資料庫版本密碼的欄位名稱不一樣 # 我的資料庫版本是5.7.21,user表中的密碼欄位是:authentication_string mysql> select version(); +-------------------------+ | version() | +-------------------------+ | 5.7.21-0ubuntu0.16.04.1 | +-------------------------+ 1 row in set (0.00 sec) # 可以通過以下命令檢視user表的密碼欄位名稱 mysql> show create table user\G;
5、再次修改my.cnf檔案
$ vim /etc/mysql/my.cnf
[mysqld]
# skip-grant-tables
6、再次重啟mysql
$ vim /etc/mysql/my.cnf
[mysqld]
# skip-grant-tables