Mysql multi-instance operation
Mysql implements a server in a multi-instance way, running mysql with different data files on different ports, which are independent of each other.
1. Close the mysql:service mysqd stop of the default port 3306.
2. Copy or create a data file
# copy the existing mysql database file # my in / var/lib/mysql, copy one to the mysql_3307 folder [root@xuegod63 ~] # cp-r / var/lib/mysql / var/lib/mysql_3307
# create a new empty database [root@xuegod63 ~] # mkdir / var/lib/mysql_3307 [root@xuegod63 ~] # mysql_install_db--datadir=/var/lib/mysql_3307-- user=mysql
3. Assign mysql users and user groups to data files
[root@xuegod63] # chown-R mysql.mysql / var/lib/mysql_3307
4. Create a configuration cnf file for multi, which is used to start the mysql instance (such as 3307) to load and execute.
[root@xuegod63 ~] # touch / usr/local/my_multi.cnf
Write the configuration you want in the file, which is typical as follows:
[mysqld_multi]
Mysqld = / usr/bin/mysqld_safe
Mysqladmin = / usr/bin/mysqladmin
User = root
Password = 123456
[mysqld3307]
Socket = / tmp/mysql_3307.sock
Port = 3307
Pid-file = / var/lib/mysql_3307/3307.pid
Datadir = / var/lib/mysql_3307/
Log = / var/lib/mysql_3307/3307.log
Character-set-server = utf8
User = mysql
5. Start your multi-instance
[root@xuegod63 ~] # mysqld_multi--defaults-extra-file=/usr/local/my_multi.cnf start 3307
6. Check whether the startup is successful
[root@xuegod63 Desktop] # netstat-natup | grep mysql
Tcp 0 0 0.0.0.0 3307 0.0.0.015 * LISTEN 3450/mysqld
If you do not find the mysql instance of the port number you want, check the / var/lib/mysql_3307/3307.log file to troubleshoot the problem
7. Set a new password
[root@xuegod63] # mysqladmin-uroot-S/tmp/mysql_3307.sock password 123456
8. Log in to your new instance
[root@xuegod63] # mysql-uroot-S / tmp/mysql_3307.sock-p
Enter password:123456
Confirm again whether your instance is using the data of the mysql_3307 folder.
It is found that a new instance has been started.
Then let's start the original example: service mysqld restart
Then let's see if two instances are started:
OK, we found that both ports of both instances have been started