MySQL Multi-instance
Here select multiple profiles, multiple boot files, multiple data files this scenario
Another option is to do it in the same configuration file.
Use the/data directory as the total root directory for MySQL multiple instances, and then plan for different MySQL
The instance port number is/data below the level two directory, different port number is different instance directory,
To distinguish between different instances, the directory under Level two contains MySQL data files, configuration files and startup files
1. Create a MySQL multi-instance directory:
Mkdir-p/data/{3306,3307}/data
[Email protected] mysql]# Tree/data
/data
├──3306
│├──data
│└──my.cnf
└──3307
├──data
└──my.cnf
Chkconfig mysqld off
Rm-f/etc/init.d/mysqld
/bin/cp/soft/src/mysql-5.5.55/support-files/my-small.cnf/data/3306/my.cnf
/bin/cp/soft/src/mysql-5.5.55/support-files/my-small.cnf/data/3307/my.cnf
Startup of multi-instance startup files MySQL Service essence:
Mysqld_safe--defaults-file=/data/3306/my.cnf 2>&1 >/dev/null
Mysqld_safe--defaults-file=/data/3307/my.cnf 2>&1 >/dev/null
Multi-instance startup file stop MySQL service in essence: (Smooth stop database)
Mysqladmin-u root-p123456-s/data/3306/mysql.sock shutdown
Mysqladmin-u root-p123456-s/data/3307/mysql.sock shutdown
To develop a startup script:
vi/data/3306/db
cp/data/3306/db/data/3307/db
The script is as follows:
#!/bin/bash
#init
port=3307
Mysql_user= "Root"
Mysql_pwd= "123456"
Cmdpath= "/install/mysql/bin"
mysql_sock= "/data/${port}/mysql.sock"
#startup function
Function_start_mysql ()
{
if [!-e "$mysql _sock"];then
printf "Starting mysql...\n";
/bin/sh ${cmdpath}/mysqld_safe--defaults-file=/data/${port}/my.cnf 2>&1 >/dev/null &
Else
printf "MySQL is running...\n"
Exit
Fi
}
#stop function
Function_stop_mysql ()
{
if [!-e "$mysql _sock"];then
printf "MySQL is stoped...\n"
Exit
Else
printf "stoping mysql...\n"
${cmdpath}/mysqladmin-u ${mysql_user}-p${mysql_pwd}-s/data/${port}/mysql.sock shutdown
Fi
}
#restart function
Function_restart_mysql ()
{
printf "Restarting mysql...\n"
Function_stop_mysql
Sleep 2
Function_start_mysql
}
Case $ in
Start
Function_start_mysql
;;
Stop
Function_stop_mysql
;;
Restart
Function_restart_mysql
;;
*)
printf "Usage:/data/${port}/mysql {start|stop|restart}\n"
Esac
Authorized:
Chown-r Mysql.mysql/data
find/data/-type f-name "db" |xargs chmod 700
Initialization
cd/install/mysql/scripts/
./mysql_install_db--basedir=/install/mysql--datadir=/data/3306/data--user=mysql
./mysql_install_db--basedir=/install/mysql--datadir=/data/3307/data--user=mysql
MySQL multi-instance login database to enlarge s designated socket
Mysql-s/data/3306/mysql.sock
Mysql-s/data/3307/mysql.sock
Multi-instance Setup password
Mysqladmin-u root-s/data/3306/mysql.sock password ' 123456 '
Mysqladmin-u root-s/data/3307/mysql.sock password ' 123456 '
Local:
Mysql-uroot-p123456-s/data/3306/mysql.sock
Mysql-uroot-p123456-s/data/3307/mysql.sock
Remote:
Mysql-uremoteuser-p123456-h Host-p 3306
Mysql-uremoteuser-p123456-h Host-p 3307
CENTOS6 mysql5.5 Multi-instance