This article describes how to create multiple instances of MySQL 5.6 in a CentOS 7 environment. Share with you for your reference, the details are as follows: 1. MySQL installation directory description mysql5.6 is installed as a binary installation package in /data/mysql56. The data directory is /data/mysql56/data. The configuration file is /etc/my.cnf. 2. Multi-Instance Directory Description
> mkdir -p /mysql-instance/3308/data > mkdir -p /mysql-instance/3309/data 3. Copy the configuration file to the instance directory > cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3308/my.cnf > cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3309/my.cnf 4. Modify the configuration file > vi /mysql-instance/3308/my.cnf > vi /mysql-instance/3309/my.cnf [client] port = 3308 socket = /mysql-instance/3308/mysql.sock [mysql] no-auto-rehash [mysqld] user = mysql port = 3308 socket = /mysql-instance/3308/mysql.sock basedir = /data/mysql56 datadir = /mysql-instance/3308/data pid-file = /mysql-instance/3308/mysql.pid relay-log = /mysql-instance/3308/relay-bin relay-log-info-file = /mysql-instance/3308/relay-log.info server-id = 12 [mysqld_safe] log-error = /mysql-instance/3308/mysql.err pid-file = /mysql-instance/3308/mysql.pid The configuration of 3309 is the same as above, just replace 3308 with 3309 5. Create MySQL multi-instance startup file >vi /mysql-instance/3308/mysql >vi /mysql-instance/3309/mysql #!/bin/sh port=3308 mysql_user="root" #Please fill in your own database password mysql_pwd="123456" cmd_path="/data/mysql56/bin" mysql_sock="/mysql-instance/${port}/mysql.sock" mysql_start() { if [ ! -e "$mysql_sock" ];then printf "mysql start ... \n" /bin/sh ${cmd_path}/mysqld_safe --defaults-file=/mysql-instance/${port}/my.cnf 2>&1 > /dev/null & else printf "mysql is running ... \n" exit fi } mysql_stop() { if [ ! -e "$mysql_sock" ];then printf "mysql is stopped ... \n" exit else printf "mysql stop ... \n" ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /mysql-instance/${port}/mysql.sock shutdown fi } mysql_restart() { printf "mysql restart ... \n" mysql_stop sleep 2 mysql_start } case $1 in start) mysql_start ;; stop)mysql_stop;; restart)mysql_restart ;; *) printf "usage: /data/${port}/mysql {start|stop|restart}\n" esac 6. Authorize mysql user directory permissions > chown -R mysql.mysql /mysql-instance > chmod 700 /mysql-instance/3308/mysql > chmod 700 /mysql-instance/3309/mysql 7. Initialize MySQL multi-instance database files > cd /daa/mysql56/scripts > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3308/data --user=mysql > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3309/data --user=mysql 8. Start multiple MySQL instances > /mysql-instance/3308/mysql start > /mysql-instance/3309/mysql start > netstat -lntup|grep 330 9. Log in to the MySQL instance > mysql -uroot -p -S /mysql-instance/3308/mysql.sock Readers who are interested in more MySQL-related content can check out the following topics on this site: "MySQL query skills", "MySQL common functions summary", "MySQL log operation skills", "MySQL transaction operation skills summary", "MySQL stored procedure skills" and "MySQL database lock related skills summary" I hope this article will be helpful to everyone's MySQL database design. You may also be interested in:
|
<<: Vue uses rules to implement form field validation
>>: Analysis of the principles and usage of Linux hard links and soft links
Sometimes you may need to modify or add exposed p...
Simple description Since it was built with Centos...
1. Create a Docker network docker network create ...
First, understand a method: Entering a Docker con...
In fact, this problem has already popped up when I...
Front-end technology layer (The picture is a bit e...
Whether it is Samba service or NFS service, the m...
1. z-index is invalid in IE6. In CSS, the z-index...
Recently, two accounts on the server were hacked ...
Preface So I wrote this blog. This blog also reco...
Use the system crontab to execute backup files re...
When doing database statistics, you often need to...
The warning points in this article have nothing t...
1. CSS background tag 1. Set the background color...
Drag and drop is a common function in the front e...