MariaDB multi-instance and MariaDB instance
1. Install MariaDB in yum and start
yum install MariaDB-server
systemctl start mariadb.service
2. Create a directory by case and set the owner Group
Store configuration files and databases by case
mkdir -pv /mysqldb/{3306,3307,3308}/{etc,socket,pid,log,data}
Set directory owner Group
chown -R mysql.mysql /mysqldb
3. Create Database Files
Mysql-e 'show variables like "basedir"; '# query the Mariadb installation directory
Mysql_install_db -- datadir =/mysqldb/3306/data -- user = mysql -- basedir =/usr
Mysql_install_db -- datadir =/mysqldb/3307/data -- user = mysql -- basedir =/usr
Mysql_install_db -- datadir =/mysqldb/3308/data -- user = mysql -- basedir =/usr
Iv. Configuration File
cp /etc/my.cnf /mysqldb/3306/etc/cp /etc/my.cnf /mysqldb/3307/etc/cp /etc/my.cnf /mysqldb/3308/etc/
Modify configuration file
The same is true for 3307 3308. You need to change the port and directory location.
5. service scripts
#! /Bin/bashport = 3306mysql_user = "root" mysql_pwd = "" cmd_path = "/usr/bin" # You can use which mysqld_safe to query metrics = "/mysqldb" mysql_sock = "$ {metrics }/$ {port}/socket/mysql. sock "function_start_mysql () {if [! -E "$ mysql_sock"]; then printf "Starting MySQL... \ n "$ {export _path}/mysqld_safe -- defaults-file =$ {mysql_basedir}/$ {port}/etc/my. cnf &>/dev/null & else printf "MySQL is running... \ n "exit fi} function_stop_mysql () {if [! -E "$ mysql_sock"]; then printf "MySQL is stopped... \ n "exit else printf" Stoping MySQL... \ n "$ {cmd_path}/mysqladmin-u $ {mysql_user}-p $ {mysql_pwd}-S $ {mysql_sock} shutdown fi} function_restart_mysql () {printf "Restarting MySQL... \ n "function_stop_mysql sleep 2 function_start_mysql} case $1 instart) function_start_mysql; stop) function_stop_mysql; restart) function_restart_mysql; *) printf" Usage: $ {mysql_basedir}/$ {port}/bin/mysqld {start | stop | restart} \ n "esac
Set permissions
The same is true for 3307,3308. You need to change the port number.
6. Start the Service (pay attention to the need to stop the Mariadb service in the Multi-case column to prevent conflicts)
/mysqldb/3306/mysqld start/mysqldb/3307/mysqld start/mysqldb/3308/mysqld start
VII. test connection
mysql -S /mysqldb/3306/socket/mysql.sock
mysql -S /mysqldb/3307/socket/mysql.sock
mysql -S /mysqldb/3308/socket/mysql.sock