1. 程式人生 > 其它 >二進位制安裝mariadb-10.6.11

二進位制安裝mariadb-10.6.11

二進位制安裝MariaBD

1.源下載

# 官方源下載不方便這裡使用清華源
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb/mariadb-10.6.11/bintar-linux-systemd-x86_64/mariadb-10.6.11-linux-systemd-x86_64.tar.gz

2.解壓建立軟連線

# 解壓安裝包
tar -xvf mariadb-10.6.11-linux-systemd-x86_64.tar.gz -C /usr/local/
ln -vs /usr/local/mariadb-10.6.11-linux-systemd-x86_64/ /usr/local/mysql

3.建立使用者 建立資料夾

# 建立組及使用者
groupadd -g 1002 mysql
useradd -s /sbin/nologin -g mysql -u 1002 -M mysql

# 建立資料夾
mkdir -p /usr/local/mysql/{data,logs,tmp}
chown -R mysql.mysql /usr/local/mysql/

4.建立環境變數

# 設定環境變數
echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
. /etc/profile.d/mysql.sh

# 加入systemd管理
cp /usr/local/mysql/support-files/systemd/mysqld.service /usr/lib/systemd/system/

5.建立配置檔案

[root@node2 ~]# vim /etc/my.cnf
[client]
port = 3306
default-character-set = utf8mb4

[mysqld]
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data/
innodb_buffer_pool_size=128M
port=3306
symbolic-links=0

[mysqld_safe]
log-bin = mysql-bin
log-error=/usr/local/mysql/logs/mysql.log

6.初始化,安全初始化資料庫

# 初始化資料庫
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/ --user=mysql

# 安全初始化
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.
# 輸入root密碼開始初始化預設沒密碼 直接回車就行
Enter current password for root (enter for none): 

# 輸入y開始初始化
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] y

# 輸入y開始修改root密碼
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y

# 輸入y刪除匿名使用者
Remove anonymous users? [Y/n] y
 ... Success!

# 輸入y禁止root遠端登入
Disallow root login remotely? [Y/n] y
 ... Success!

# 輸入y刪除測試資料庫
Remove test database and access to it? [Y/n] y
 - Dropping test database...

# 輸入y重新整理資料庫
Reload privilege tables now? [Y/n] y
 ... Success!

7.登入測試

[root@node2 ~]# mysql -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.6.11-MariaDB MariaDB Server

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)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.001 sec)

參考連結

https://blog.csdn.net/cnskylee/article/details/124174078