当前位置:网站首页>Configuring multiple instances of MySQL under Linux
Configuring multiple instances of MySQL under Linux
2022-06-28 07:46:00 【New objects first】
Document directory
Two . Linux The configuration MySQL Multiple instances
- 2.1 Create the relevant directory and click OK
- 2.2 Modify the configuration file
- 2.3 Initialize and start the specified instance
- 2.4 Change password and open remote connection
- 2.5 Remote connection test
- 2.6 Multi instance start / stop scripts
One . MySQL install
MySQL Please refer to this blog for installation :
linux Lower installation MySQL5.7 And summarize the problems encountered
Two . Linux The configuration MySQL Multiple instances
Be careful : This part needs to be in ( One ) Based on
My multi instance directory is planned as follows :
| Path action | Absolute position |
|---|---|
| mysql The installation path | /opt/modules/mysql |
| Each instance data directory | /opt/modules/mysql/data/{port} |
| Each instance log file | /opt/modules/mysql/logs/{port}/error.log |
| Generated at runtime pid file | /opt/modules/mysql/run/{port}/mysqld.pid |
| socket file | /var/lib/mysql/{port}/mysql.sock |
| Configuration files for each instance | /etc/mysql/{port}/my.cnf |
2.1 Create the relevant directory and click OK
# Here we use 3308 An example of a port number is , For example, configure other port numbers , Just change the port number in the command
mkdir -p /opt/modules/mysql/data/3308
mkdir -p /opt/modules/mysql/run/3308
mkdir -p /opt/modules/mysql/logs/3308
touch /opt/modules/mysql/logs/3308/error.log
mkdir -p /var/lib/mysql/3308
chown -R mysql:mysql /var/lib/mysql
chown -R mysql:mysql /opt/modules/mysql
chmod -R 755 /opt/modules/mysql
mkdir -p /etc/mysql/3308
2.2 Modify the configuration file
vi /etc/mysql/3308/my.cnf
#3308 To configure , Be careful : Different instances only need to add the 3308 Replace it
[mysqld]
datadir=/opt/modules/mysql/data/3308
port=3308
socket=/var/lib/mysql/3308/mysql.sock
basedir=/opt/modules/mysql
server-id=3308
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
max_connections=400
innodb_file_per_table=64
lower_case_table_names=1
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/opt/modules/mysql/logs/3308/error.log
pid-file=/opt/modules/mysql/run/3308/mysqld.pid
[client]
port=3308
socket=/var/lib/mysql/3308/mysql.sock
2.3 Initialize and start the specified instance
# initialization Here you need to remember the last string output by the command , It as a MySQL Initial password for login stay MySQL Install under directory bin Directory execution
./mysqld --initialize --user=mysql --datadir=/opt/modules/mysql/data/3308 --basedir=/opt/modules/mysql
# start-up MySQL You need to specify the startup configuration file
nohup /bin/sh /opt/modules/mysql/bin/mysqld_safe --defaults-file=/etc/mysql/3308/my.cnf --user=mysql &
2.4 Change password and open remote connection
# Because here we are not by default 3306 Port boot , So you need to specify socket file
# The password entered is... Above mysql The last string output from the initialization command
mysql -uroot -p -S /var/lib/mysql/3308/mysql.sock
# Set the password
mysql> set password for root@localhost = password('yourpassword');
# Open remote connection
mysql> use mysql;
mysql> update user set user.Host='%' where user.User='root';
mysql> flush privileges;
2.5 Remote connection test
Use SQLyog Test remote connection , make new connection
Enter the connection information , And port number

Click test connection :
You can see , The connection is normal ,Linux The configuration mysql Multiple instances succeeded
2.6 Multi instance start / stop scripts
When we deploy multiple servers on the same server MySQL When an instance , Multiple MySQL The maintenance of instances can become very complex
Based on the above, we are right to MySQL Directory planning , We can provide a unified start stop script maintenance for these instances
( Pass in the port number as a parameter to distinguish different MySQL example )
vim /opt/modules/mysql/bin/mysql_instance.sh
#!/bin/bash
# MySQL Multi instance unified start / stop script Parameters 1: Carry out orders (start|stop|restart) Parameters 2: Port number ( Start and stop the corresponding instance through the port number )
# Parameters 3: mysql user name , Parameters 4: mysql password
port=$2
mysql_user=$3
mysql_pwd=$4
cmd_path="/opt/modules/mysql/bin"
mysql_sock="/var/lib/mysql/${port}/mysql.sock"
#startup function
function_start_mysql(){
if [ ! -e "$mysql_sock" ];then
printf "Starting Mysql...\n"
/bin/sh ${cmd_path}/mysqld_safe --defaults-file=/etc/mysql/${port}/my.cnf 2>&1 >/dev/null & # Start command
else
printf "Mysql is running...\n"
exit
fi
}
#stop function
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 # Stop the order
fi
}
#restart function
function_restart_mysql(){
printf "Restart Mysql...\n"
function_stop_mysql
sleep 2
function_start_mysql
}
case $1 in
start)
function_start_mysql
;;
stop)
function_stop_mysql
;;
restart)
function_restart_mysql
;;
*)
printf "Usage:${cmd_path}/mysql.sh {start|stop|restart}\n"
esac
Script execution example :
# start-up 3308 Port number mysql example
sh /opt/modules/mysql/bin/mysql_instance.sh start 3308 root 123456
# restart
sh /opt/modules/mysql/bin/mysql_instance.sh restart 3308 root 123456
#
边栏推荐
- Section 9: dual core startup of zynq
- Mysql8.0 and mysql5.0 accessing JDBC connections
- HJ delete the character with the least number of occurrences in the string
- Is it reliable to register and open an account for stock speculation? Is it safe?
- Conversion between HJ integer and IP address
- 阿里云服务器创建快照、回滚磁盘
- Es data export CSV file
- Introduction and several months' experience of extending the solution thanos of Prometheus
- 腾讯下半年继续裁员,所有事业群至少缩减 10%,对此你怎么看?关注者
- kubernetes删除pod的流程的源码简析
猜你喜欢

Uninstall and reinstall the latest version of MySQL database. The test is valid

Alibaba cloud server creates snapshots and rolls back disks

asp. Net datalist to display product information and pictures

No suspense about the No. 1 Internet company overtime table

Sword finger offer|: linked list (simple)

"Three routines" of digital collection market

阿里云服务器创建快照、回滚磁盘

Sentinel mechanism of redis cluster

Leetcode learning records

golang gin框架进行分块传输
随机推荐
R language hitters data analysis
Mysql57 zip file installation
HJ字符串排序
Cloud native: cloud computing technology is upgraded again to open an era of comprehensive cloud development
Conversion between HJ integer and IP address
Unity UI shadow component
Sentinel mechanism of redis cluster
Introduction and several months' experience of extending the solution thanos of Prometheus
asp. Net datalist when there are multiple data displays
Safety training is the greatest benefit for employees! 2022 induction safety training for new employees
es数据导出csv文件
Kubernetes cluster command line tool kubectl
SOC serial port configuration
安全培训是员工最大的福利!2022新员工入职安全培训全员篇
ACM笔记
阿里云服务器创建快照、回滚磁盘
HJ进制转换
Helloword routine for ROS
Study notes 22/1/11
ES6 use of return in arrow function