MariaDB tar包安裝 配置


MariaDB起初是MySQL的一個復刻版,由社區開發,有商業支持,旨在繼續保持在GUN GPL下開源。MariaDB的開發是由MySQL的一些原始開發者領導的,他們擔心甲骨文收購MySQL后會不繼續開源。

MariaDB官網:https://mariadb.org/

一.獲取安裝包並解壓

獲取安裝包的方式有很多,可以wget,也可以直接下載到本地,以目前最新的版本為例,下載地址為:https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/bintar-linux-x86_64/mariadb-10.5.8-linux-x86_64.tar.gz

下載完成之后,tar解壓,例如

[root@localhost opt]# pwd
/opt
# 下載
[root@localhost opt]# wget https://downloads.mariadb.com/MariaDB/mariadb-10.5.8/bintar-linux-x86_64/mariadb-10.5.8-linux-x86_64.tar.gz
# 解壓
[root@localhost opt]# tar -zxf mariadb-10.5.8-linux-x86_64.tar.gz 

[root@localhost opt]# ls

mariadb-10.5.8-linux-x86_64
mariadb-10.5.8-linux-x86_64.tar.gz
# 解壓后可以把文件夾重命名為想要的basedir
[root@localhost opt]# mv mariadb-10.5.8-linux-x86_64 mariadb-10.5.8-33068

我們可以看一下basedir的結構

[root@localhost mariadb-10.5.8-33068]# ls bin CREDITS include lib mysql-test README-wsrep share support-files
COPYING EXCEPTIONS-CLIENT INSTALL-BINARY man README.md scripts sql-bench THIRDPARTY

 

里面比較常用重要的有bin,scripts,support-files這幾個文件夾

bin目錄下面,是一些可執行程序,例如mariabackup(備份還原工具,后面單獨分析),mysql(客戶端工具),mysqladmin,mysqlbinlog(日志分析工具),mysqldump(備份還原)等等

scripts目錄下面是數據庫初始化工具,目前是mariadb-install-db和mysql_install_db,它兩其實是一樣的

support-files目錄下 mysql.server可作為啟動程序

二.准備用戶和組,datadir和basedir

basedir即為上一步的/opt/mariadb-10.5.8-33068

datadir我選擇的是/data01/data/data33068需要注意的是,給datadir要賦予正確的用戶和組權限,否則會出現 Permission denied 問題

[root@localhost opt]# groupadd mysql
[root@localhost opt]# useradd -g mysql mysql
[root@localhost data]# mkdir /data01/data/data33068 
[root@localhost data]#
chown -R mysql.mysql /data01/data/data33068

三.准備配置文件並使用配置文件初始化

初始化的時候,使用my.cnf,不使用默認配置

使用自定義my.cnf的時候,需要注意my.cnf的讀取順序, /etc/my.cnf /etc/mysql/my.cnf 這兩個文件最好不要存在 

Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf

配置文件僅作參考,具體參數后面再分析

 

[root@localhost mariadb-10.5.8-33068]# cat /opt/mariadb-10.5.8-33068/my.cnf 
[client]
port            = 33068
socket          = /data01/data/data33068/mysql33068.sock

# The MySQL server
[mysqld]
port            = 33068
socket          = /data01/data/data33068/mysql33068.sock
skip-external-locking
skip_name_resolve
thread_handling=pool-of-threads
relay_log_recovery=1
low-priority-updates
event_scheduler = ON
key_buffer_size = 32M
max_allowed_packet = 32M
table_open_cache = 2048
sort_buffer_size = 8M
read_buffer_size = 8M
read_rnd_buffer_size = 8M
join_buffer_size=8M
myisam_sort_buffer_size = 32M
thread_cache_size = 2000
wait_timeout =15
max_connections     =  99999
max_connect_errors  =   9999
max_heap_table_size =  8M
group_concat_max_len = 102400
tmp_table_size = 8M
datadir=/data01/data/data33068
log-error=/data01/data/data33068/mysqld33068.log
log-bin=33068
server-id        = 1
relay-log           = relay-bin
relay-log-index     = relay-bin
binlog_format=row
expire_logs_days=4
innodb_file_per_table=1
innodb_data_home_dir=/data01/data/data33068
innodb_data_file_path=ibdata1:1G:autoextend
innodb_buffer_pool_instances=4
innodb_buffer_pool_size = 512M
innodb_log_group_home_dir=/data01/data/data33068
innodb_log_files_in_group = 3
innodb_log_file_size =1G
innodb_log_buffer_size = 50M
innodb_flush_method=O_DIRECT
innodb_thread_concurrency=16
innodb_max_dirty_pages_pct=75
innodb_flush_log_at_trx_commit = 2


[mysqldump]
quick
max_allowed_packet = 16M

[mysql]
no-auto-rehash
prompt=MariaDB [\d]>

[myisamchk]
key_buffer_size = 25M
sort_buffer_size = 25M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
初始化
[root@localhost mariadb-10.5.8-33068]# /opt/mariadb-10.5.8-33068/scripts/mysql_install_db --defaults-file=/opt/mariadb-10.5.8-33068/my.cnf --basedir=/opt/mariadb-10.5.8-33068/ --datadir=/data01/data/data33068/ --user=mysql

若初始化失敗,需要根據提示在錯誤日志里面找問題

四.配置啟動腳本並啟動

[root@localhost support-files]# cp -rp /opt/mariadb-10.5.8-33068/support-files/mysql.server /etc/init.d/mysqld33068

 # copy完成之后需要更改下面三行(行號僅供參考) 45 basedir=/opt/mariadb-10.5.8-33068
46 datadir=/data01/data/data33068 261     if $bindir/mysqladmin -S /data01/data/data33068/mysql33068.sock ping >/dev/null 2>&1; then

#也可以使用下面語句進行更改

sed -i "s/^basedir\=/basedir\=\"\/opt\/mariadb-10.5.8-33068\"/g" /etc/init.d/mysqld33068
sed -i "s/^datadir=/datadir=\"\/data01\/data\/data33068\"/g" /etc/init.d/mysqld33068
sed -i "s/mysqladmin/mysqladmin -S \"\/data01\/data\/data33068\/mysql33068.sock\"/g"

 

打開服務

/etc/init.d/mysqld33068 start

即可登陸使用,密碼為空

/opt/mariadb-10.5.8-33068/bin/mariadb -S /data01/data/data33068/mysql33068.sock -uroot -p

Enter password: 
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.5.8-MariaDB-log 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 |
| test |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> Ctrl-C -- exit!
Aborted

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM