如何在 Ubuntu 20.04 上安裝 MySQL 8.0


MySQL 是一種流行的關係數據庫管理系統,用於以表格形式存儲結構化數據。這是一個使用 SQL(結構化查詢語言)語句進行交互的開源數據庫服務器。 MySQL 根據 GNU 通用公共許可證的條款免費提供。

本教程將幫助您在 Ubuntu 20.04 LTSFocal 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。

選擇正確的版本後,使用鍵盤上的上下鍵將光標移動到最後一行,OK。 按 Enter 繼續處理。

如果選擇了錯誤的版本。嵌入 dpkg-reconfigure mysql-apt-config 安裝軟件包後再次獲取此窗口的命令。

步驟 2-在 Ubuntu 上安裝 MySQL 8

系統已準備好安裝 MySQL。按照以下命令在您的 Ubuntu 20.04 Linux 系統上安裝 MySQL 8。

  1. 添加 GPG 密鑰 – 通過運行以下命令在 Ubuntu 18.04 系統上安裝 MySQL:
    sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8C718D3B5072E1F5 
    
  2. 緩存更新—— 運行以下命令來更新系統的 apt 緩存。
    sudo apt update  
    
  3. 安裝 MySQL- 最後,安裝 MySQL 服務器包。
    sudo apt install mysql-server 
    

安裝過程會提示您將root密碼設置為默認值。[セキュリティパスワードの入力]帶窗戶[パスワードの確認]窗戶是一樣的。這將是登錄 MySQL 服務器所需的 MySQL root 用戶的密碼。

Ubuntu 18.04 上的 MySQL

步驟 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>

結論是

完成本教程後,MySQL 8 將安裝在您的 Ubuntu 20.04 Linux 系統上。即使您可以從終端訪問 MySQL,您仍然可以安裝和使用 phpMyAdmin。

鼓勵生產用戶定期安排數據庫備份。此腳本可幫助您安排 MySQL 數據庫的備份並將它們複製到遠程位置。



Source link