在 Linux 系統上安裝 MariaDB
本篇記錄在 Debain
及 Rocky Linux
環境下安裝 MariaDB
服務
112.09.20 修改版本
112.12.03 因 MariaDB 有公告長期維護版本是五年,其他版本都是維護都是一年,那本篇會以長期維護版本做為記錄。
2024.07.18 修改資料庫版本為 11.04 為主要來源庫及增加 Rocky Linux 系列。
運行環境
環境都是在 「Proxmox VE 」 虛擬系統上架設,都是以 「 LXC 」模式為主,除非有特殊狀況會告知使用 「 VM 」 模式
- 系統環境: Debian
- 資料庫服務: MariaDB 10.11、11.04
安裝過程
- MaraiDB 官方下載點
Debain 系列
- 新增 MariaDB 套件庫金鑰
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 套件庫
10.11
- Debian 10
vim /etc/apt/sources.list.d/mariadb.sources
# MariaDB 10.11 repository list - created 2024-07-19 03:26 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://ftp.ubuntu-tw.org/mirror/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 2024-07-19 03:26 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://ftp.ubuntu-tw.org/mirror/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 2024-07-19 03:27 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://ftp.ubuntu-tw.org/mirror/mariadb/repo/10.11/debian Suites: bookworm Components: main Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
- Debian 10
-
新增 MariaDB 套件庫
11.04
- Debian 10
vim /etc/apt/sources.list.d/mariadb.sources
# MariaDB 11.4 repository list - created 2024-07-18 14:36 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/11.4/debian URIs: https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.4/debian Suites: buster Components: main Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
- Debian 11
vim /etc/apt/sources.list.d/mariadb.sources
# MariaDB 11.4 repository list - created 2024-07-18 14:36 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/11.4/debian URIs: https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.4/debian Suites: bullseye Components: main Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
- Debian 12
vim /etc/apt/sources.list.d/mariadb.sources
# MariaDB 11.4 repository list - created 2024-07-18 14:37 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/11.4/debian URIs: https://ftp.ubuntu-tw.org/mirror/mariadb/repo/11.4/debian Suites: bookworm Components: main Signed-By: /etc/apt/keyrings/mariadb-keyring.pgp
- Debian 10
Rocky Linux 系列
-
新增 MariaDB 套件庫
10.11
- Rocky Linux 8
vim /etc/yum.repos.d/MariaDB.repo
# MariaDB 10.11 RedHatEnterpriseLinux repository list - created 2024-07-19 03:36 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch baseurl = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/10.11/rhel/$releasever/$basearch module_hotfixes = 1 # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
- Rocky Linux 9
vim /etc/yum.repos.d/MariaDB.repo
MariaDB 10.11 RedHatEnterpriseLinux repository list - created 2024-07-19 03:37 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/10.11/rhel/$releasever/$basearch baseurl = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/10.11/rhel/$releasever/$basearch # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
- Rocky Linux 8
-
新增 MariaDB 套件庫
11.04
- Rocky Linux 8
vim /etc/yum.repos.d/MariaDB.repo
MariaDB 11.4 RedHatEnterpriseLinux repository list - created 2024-07-19 03:38 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/11.4/rhel/$releasever/$basearch baseurl = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/11.4/rhel/$releasever/$basearch module_hotfixes = 1 # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
- Rocky Linux 9
vim /etc/yum.repos.d/MariaDB.repo
MariaDB 11.4 RedHatEnterpriseLinux repository list - created 2024-07-19 03:38 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB # rpm.mariadb.org is a dynamic mirror if your preferred mirror goes offline. See https://mariadb.org/mirrorbits/ for details. # baseurl = https://rpm.mariadb.org/11.4/rhel/$releasever/$basearch baseurl = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/11.4/rhel/$releasever/$basearch # gpgkey = https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB gpgkey = https://ftp.ubuntu-tw.org/mirror/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
- Rocky Linux 8
-
更新系統並且安裝 MariaDB
- Debian
sudo apt-get update && sudo apt-get install mariadb-server -y
- Rocky Linux
sudo dnf install MariaDB-server MariaDB-client -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 可空白登入