跳到主內容

在 Debian 系統上安裝 MariaDB

  本篇記錄在 Debain 環境下安裝 MariaDB 服務

112.09.20 修改版本

112.12.03 因 MariaDB 有公告長期維護版本是五年,其他版本都是維護都是一年,那本篇會以長期維護版本做為記錄。

運行環境


  環境都是在 「Proxmox VE 」 虛擬系統上架設,都是以 「 LXC 」模式為主,除非有特殊狀況會告知使用 「 VM 」 模式

  • 系統環境: Debian
  • 資料庫服務: MariaDB 10.11

安裝過程


sudo apt-get install apt-transport-https curl -y
sudo mkdir -p /etc/apt/keyrings
sudo curl -o /etc/apt/keyrings/mariadb-keyring.pgp 'https://mariadb.org/mariadb_release_signing_key.pgp'
  • 新增 MariaDB 套件庫

    • Debian 10 vim /etc/apt/sources.list.d/mariadb.sources
    # MariaDB 10.11 repository list - created 2023-12-03 02:00 UTC
    # https://mariadb.org/download/
    X-Repolib-Name: MariaDB
    Types: deb
    # deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
    # URIs: https://deb.mariadb.org/10.11/debian
    URIs: https://tw1.mirror.blendbyte.net/mariadb/repo/10.11/debian
    Suites: buster
    Components: main
    Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
    
    • Debian 11 vim /etc/apt/sources.list.d/mariadb.sources
    # MariaDB 10.11 repository list - created 2023-12-03 02:01 UTC
    # https://mariadb.org/download/
    X-Repolib-Name: MariaDB
    Types: deb
    # deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
    # URIs: https://deb.mariadb.org/10.11/debian
    URIs: https://tw1.mirror.blendbyte.net/mariadb/repo/10.11/debian
    Suites: bullseye
    Components: main
    Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
    
    • Debian 12 vim /etc/apt/sources.list.d/mariadb.sources
    # MariaDB 10.11 repository list - created 2023-12-03 02:01 UTC
    # https://mariadb.org/download/
    X-Repolib-Name: MariaDB
    Types: deb
    # deb.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details.
    # URIs: https://deb.mariadb.org/10.11/debian
    URIs: https://tw1.mirror.blendbyte.net/mariadb/repo/10.11/debian
    Suites: bookworm
    Components: main
    Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
    
  • 更新系統並且安裝 MariaDB

sudo apt-get update && sudo apt-get install mariadb-server -y
  • 啟動服務
sudo systemctl enable --now mariadb
  • 資料庫基本設定,那在 MariaDB 10.5 以上版本官方已經改用 mariadb-secure-installation 那 MariaDB 10.4 以下還是可以用 mysql_secure_installation 來執行, MaridDB 官方說明
mariadb-secure-installation   # 設定資料庫的root密碼

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]    <----- 直接按下 enter 鍵
Enabled successfully!
Reloading privilege tables..
 ... Success!


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

Change the root password? [Y/n]               <----- 直接按下 enter 鍵
New password:                                 <----- 輸入 root 密碼
Re-enter new password:                        <----- 再次輸入 root 密碼
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] 
 ... 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] 
 ... 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] 
 - 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] 
 ... 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!

補充說明


  • BUBU 在設定資料庫無異間發現到使用 root 帳號可以免密碼就可以登入修正方式請參考本篇進行修改 MariaDB root 可空白登入

備註





參考相關網頁