DEV Community

Cover image for CentOS 裝 MariaDB 10
Leon
Leon

Posted on • Originally published at editor.leonh.space

CentOS 裝 MariaDB 10

一樣因為 CentOS 自帶的 MariaDB 太舊,改用 CentOS Software Collections 提供的 MariaDB 10。

這篇參考〈How to Install and Configure a LEMP Stack using Software Collections on CentOS 7〉。

先安裝:

> sudo yum install rh-mariadb102
Enter fullscreen mode Exit fullscreen mode

跑起來:

> sudo systemctl start rh-mariadb102-mariadb
Enter fullscreen mode Exit fullscreen mode

讓這個 SCL 管理的 MariaDB 進入 path 內:

> source scl_source enable rh-mariadb102
Enter fullscreen mode Exit fullscreen mode

執行安裝後組態設定,應該要用 root 權限跑,但不知為何跑不了,所以改先開一個 root shell 再跑。

> sudo bash
> source /opt/rh/rh-mariadb102/enable
> mysql_secure_installation
Enter fullscreen mode Exit fullscreen mode
  1. 被問 root 密碼,在此指 DB 的 root,非 OS 的 root,目前沒有,就 Enter 過去。
  2. 設定 DB root 密碼。
  3. 關閉匿名帳號登入權限。
  4. 讓 root 只能從本機連線。
  5. 把 test 資料庫刪掉。
  6. 重載入權限表讓以上決定生效。

設定開機啟動 MariaDB:

> sudo systemctl enable rh-mariadb102-mariadb
Enter fullscreen mode Exit fullscreen mode

照 SCL 慣例,設定擋在 /etc/opt/rh/rh-mariadb102/ 內、程式等等都在 /opt/rh/rh-mariadb102/ 內。

測試一下連線:

> mysql -u root -p
Enter fullscreen mode Exit fullscreen mode

沒問題就這樣了。

最後一樣在 /etc/profile.d/ 建一支小 shell script 讓開機就自動把 SCL 的 mariadb 加到路徑內,方便執行 mysql:

# /bin/bash

source scl_source rh-mariadb102
Enter fullscreen mode Exit fullscreen mode

後面大概再裝一下 phpMyAdmin 和 mycli 就差不多了。

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

AWS Security LIVE!

Hosted by security experts, AWS Security LIVE! showcases AWS Partners tackling real-world security challenges. Join live and get your security questions answered.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️