如何在Ubuntu 20.04上安裝MariaDB

MariaDB是從流行的數據庫管理系統MySQL派生而來的開源數據庫服務器。 它取代了MySQL作為大多數Linux操作系統的默認數據庫服務器。

在這裡,我們將看到如何在Ubuntu 20.04上安裝MariaDB。

在Ubuntu 20.04上安裝MariaDB

您可以從Ubuntu存儲庫或Official MariaDB鏡像中獲取MariaDB軟件包。

  1. 安裝MariaDB v10.4 – MariaDB鏡像

  2. 安裝MariaDB v10.3 – Ubuntu存儲庫

從MariaDB鏡像安裝MariaDB

MariaDB基金會為Ubuntu 20.04提供了MariaDB v10.4。 您可以從MariaDB下載頁面中選擇任何一個鏡像進行下載。

sudo apt update

sudo apt install -y software-properties-common apt-transport-https ca-certificates

將MariaDB的簽名密鑰添加到您的系統。

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

使用add-apt-repository命令將MariaDB存儲庫添加到您的系統。

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://sfo1.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu focal main'

讀:
在Ubuntu上找不到add-apt-repository命令–快速修復

現在,使用以下命令安裝MariaDB。

sudo apt update

sudo apt install -y mariadb-server mariadb-client

使用mysql_secure_installation設置MariaDB根密碼並保護MariaDB服務器的安裝。

sudo mysql_secure_installation

輸出:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] N 
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y 
New password: *** 
Re-enter new password: *** 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y 
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

從Ubuntu存儲庫安裝MariaDB

從Ubuntu默認存儲庫安裝是一種直接的方法。 Ubuntu 20.04發布了MariaDB v10.3。

使用apt命令安裝MariaDB。

sudo apt update

sudo apt install -y mariadb-server mariadb-client

使用mysql_secure_installation設置MariaDB根密碼並保護MariaDB服務器的安裝。

sudo mysql_secure_installation

輸出:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y 
New password: *** 
Re-enter new password: *** 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] 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? [Y/n] Y 
 ... Success!

By default, MariaDB 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? [Y/n] 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? [Y/n] Y  
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

MariaDB使用Unix套接字身份驗證機制,該機制可防止其他Unix用戶登錄或使用諸如phpMyAdmin之類的應用程序訪問MariaDB根用戶。 要禁用Unix套接字認證並啟用本機密碼,請遵循以下步驟。

以MariaDB根用戶身份登錄。

sudo mysql -u root -p

無需密碼

use mysql;

update user set plugin='mysql_native_password' where user="root";

flush privileges;

quit;

現在,您可以毫無問題地以MariaDB根用戶身份登錄。

訪問MariaDB

要訪問MariaDB Shell以創建數據庫或任何與數據庫相關的活動,請在終端上運行以下命令。

sudo mysql -u root -p

輸入在確保mysql_secure_installation安裝安全時設置的MariaDB根用戶的密碼。

輸入密碼後,您將獲得MariaDB shell。

Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 58
Server version: 10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.

MariaDB [(none)]>

控制MariaDB服務

如果要啟動/停止MariaDB,可以使用以下命令。

sudo systemctl start mariadb

sudo systemctl stop mariadb

結論

就這樣。 請在評論部分分享您的反饋。

Sidebar