当前位置:网站首页>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
#
边栏推荐
- [ thanos源码分析系列 ]thanos query组件源码简析
- Unity-UI-shadow组件
- 自动化测试的生命周期是什么?
- Analyze 5 indicators of NFT project
- Kubelet garbage collection (exiting containers and unused images) source code analysis
- asp. Net datalist when there are multiple data displays
- HJ character count
- Software design of resistance test board
- Sentinel mechanism of redis cluster
- No suspense about the No. 1 Internet company overtime table
猜你喜欢

以动态规划的方式求解最长回文子串

Cloud native (to be updated)

Safety training is the greatest benefit for employees! 2022 induction safety training for new employees

Hash slot of rediscluster cluster cluster implementation principle

ACM notes

数字藏品市场“三大套路”

Solving the longest palindrome substring by dynamic programming

linux下修改mysql端口号

异或的应用。(提取出数字中最右侧的1,面试中经常用的到)

Flex layout
随机推荐
Source code analysis of kubernetes' process of deleting pod
What is the lifecycle of automated testing?
以动态规划的方式求解最长回文子串
HJ删除字符串中出现次数最少的字符
Mysql8.0 and mysql5.0 accessing JDBC connections
股票炒股注册开户靠谱吗?安全吗?
卸载重装最新版mysql数据库亲测有效
Drawing animated bubble chart with R language
Kubelet garbage collection (exiting containers and unused images) source code analysis
Explanation and application of instr() function in Oracle
SOC clock configuration
Localization SoC development plan
kubelet驱逐机制的源码分析
Modifying MySQL user name root under Linux
Software design of resistance test board
GPIO configuration of SOC
Can okcc call centers work without computers?
Co process, asyncio, asynchronous programming
Uninstall and reinstall the latest version of MySQL database. The test is valid
Makefile