MySQL的安裝過程
本人的系統是Manjaro,查詢了一下Archwiki發現,不少linux默認的SQL數據庫是MariaDB了。同時說,MySQL已經被移到了AUR庫裏面。html
按照Oracle的德行,MySQL的創始人建立了了一個MySQL的分支,MariaDB,若是MySQL閉源,MariaDB能夠馬上代替MySQL使用。所以,不難知道MariaDB是徹底兼容MySQL的。mysql
不過的話,MySQL不少項目都使用這個,最後決定安裝MySQL。linux
安裝MySQL
安裝MySQLsql
sudo pacman -S mysql
安裝後的一系列配置
查看安裝日誌
[2020-04-01T13:29:05+0800] [ALPM-SCRIPTLET] :: You need to initialize the MySQL data directory prior to starting [2020-04-01T13:29:05+0800] [ALPM-SCRIPTLET] the service. This can be done with mysqld --initialize command, e.g.: [2020-04-01T13:29:05+0800] [ALPM-SCRIPTLET] mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql [2020-04-01T13:29:05+0800] [ALPM-SCRIPTLET] :: Additionally you should secure your MySQL installation using [2020-04-01T13:29:05+0800] [ALPM-SCRIPTLET] mysql_secure_installation command after starting the mysqld service
看到須要初始化 MySQLshell
執行命令:數據庫
mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
初始化MySQL
mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
執行之後立刻就報錯了。(煩人)安全
2020-04-01T05:45:51.941236Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2020-04-01T05:45:51.941340Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 75054 2020-04-01T05:45:51.943568Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting. 2020-04-01T05:45:51.943574Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it. 2020-04-01T05:45:51.943645Z 0 [ERROR] [MY-010119] [Server] Aborting 2020-04-01T05:45:51.943786Z 0 [System] [MY-010910] [Server] /usr/bin/mysqld: Shutdown complete (mysqld 8.0.19) Source distribution.
查看 [ERROR] 信息之後發現bash
The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.url
好吧,那也只好這樣了。sudo su
切換到root帳戶下面。~~rm -rf /var/lib/mysql/*
刪除裏面的文件。~~打開文件夾cd /後面這樣安全寫var/lib
,而後刪除mysql裏面的文件rm -rf mysql/*
。後面這樣作就算出錯,也不至於把系統刪了。spa
再次初始化
mysqld --initialize --user=mysql --basedir=/usr --datadir=/var/lib/mysql
出現日誌
2020-04-01T05:52:22.017420Z 0 [Warning] [MY-010915] [Server] 'NO_ZERO_DATE', 'NO_ZERO_IN_DATE' and 'ERROR_FOR_DIVISION_BY_ZERO' sql modes should be used with strict mode. They will be merged with strict mode in a future release. 2020-04-01T05:52:22.017498Z 0 [System] [MY-013169] [Server] /usr/bin/mysqld (mysqld 8.0.19) initializing of server in progress as process 75837 2020-04-01T05:52:39.779289Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: s?2P***skGeq(這是臨時密碼)
發現,沒有[ERROR]開心的很。
啓動服務
systemctl start mysqld
沒有報錯之後就是安裝成功了。
初次登陸MySQL
重置root密碼
-
登陸
mysql -u root -p
Enter password:
密碼就是上面記錄的臨時密碼:s?2P***skGeq
-
修改密碼
進入MySQL的shell裏面之後,執行命令
ALTER USER 'root'@'localhost' IDENTIFIED BY 'root-password';
安裝mysql可視化界面
mysql有一個叫作workbench的可視化界面,感受還不錯。
sudo pacman -S mysql-workbench
參考源: