MySQL 是一種流行的關係數據庫管理系統,用於以表格形式存儲結構化數據。這是一個使用 SQL(結構化查詢語言)語句進行交互的開源數據庫服務器。 MySQL 根據 GNU 通用公共許可證的條款免費提供。
本教程將幫助您在 Ubuntu 20.04 LTS Focal Linux 系統上安裝 MySQL 8。
先決條件
需要使用 sudo 特權帳戶訪問運行的 Ubuntu 20.04 LTS 系統。然後登錄您的系統並打開一個終端。
ssh [email protected]
通過運行以下命令將當前包升級到最新版本:
sudo apt update && sudo apt upgrade
第 1 步 – 啟用 MySQL PPA
MySQL 團隊為 Ubuntu 操作系統提供了官方的 MySQL PPA。在您的 Ubuntu 18.04 系統上下載並安裝此軟件包會將 PPA 文件添加到您的系統中。通過運行以下命令啟用 PPA:
wget https://repo.mysql.com/mysql-apt-config_0.8.10-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.10-1_all.deb
安裝程序將要求您為 MySQL 版本設置默認存儲庫。 確保 MySQL-8 設置為當前選擇。要更改此設置,請轉到該行並按 Enter。
選擇正確的版本後,使用鍵盤上的向上和向下鍵將光標移動到最後一行“確定”。 按 Enter 繼續處理。
如果選擇了錯誤的版本。嵌入 dpkg-reconfigure mysql-apt-config
安裝包後使用命令再次獲取此窗口。
第 2 步 – 在 Ubuntu 上安裝 MySQL 8
您現在已準備好在您的系統上安裝 MySQL。按照以下命令在您的 Ubuntu 20.04 Linux 系統上安裝 MySQL 8。
- 添加 GPG 密鑰 – 通過運行以下命令在 Ubuntu 18.04 系統上安裝 MySQL:
sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8C718D3B5072E1F5
- 刷新緩存 – 通過運行以下命令刷新系統上的 apt 緩存:
sudo apt update
- 安裝 MySQL – 最後,安裝 MySQL 服務器包。
sudo apt install mysql-server
安裝過程將提示您將 root 密碼設置為默認值。安全密碼輸入窗口和密碼確認窗口相同。這將是登錄 MySQL 服務器所需的 MySQL root 用戶密碼。
第 3 步 – 安全 MySQL 安裝
通過在系統上運行以下命令來更改數據庫服務器安全性:這會帶來一些問題。高級安全提供所有答案 是的.
sudo mysql_secure_installation
在這裡您可以啟用/禁用驗證密碼插件,設置所需的密碼強度,刪除匿名用戶,禁止遠程root登錄,刪除和訪問測試數據庫,以及在應用更改後重新加載重新加載權限。
請參閱下面的輸出和我採取的措施。
Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Using existing password for root. Estimated strength of the password: 50 Change the password for root ? ((Press y|Y for Yes, any other key for No) : y New password: **************** Re-enter new password: **************** Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
第 4 步 – 連接到 MySQL
MySQL 服務器已安裝在您的系統上。使用命令行連接到您的 MySQL 數據庫。使用您在上述步驟中設置的 root 帳戶的密碼。
mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 9
Server version: 8.0.23 MySQL Community Server - GPL
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
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.
mysql>
結論是
完成本教程後,您將在 Ubuntu 20.04 Linux 系統上安裝 MySQL 8。即使您可以從終端訪問 MySQL,您仍然可以通過安裝 phpMyAdmin 來使用它。
建議生產用戶定期安排數據庫備份。此腳本可幫助您安排 MySQL 數據庫的備份並將它們複製到遠程位置。