D-2.1 Add an instance (3309instance)
D-2.1.1 , create a directory
# Cd/data
# mkdir 3309/data
D-2.1. 2. Create my.cnf file in/data/3309
[Client]
port=3309
Socket=/data/3309/mysql.sock
Prompt=\\[email protected] \\r:\\m:\\s->
[Mysqld]
Basedir =/mysql
DataDir =/data/3309/data
Port =3309
server_id =4
Socket =/data/3309/mysql.sock
Log-bin=/data/3309/mysql_bin
Binlog_format=mixed
#binlog-do-db=
#binlog-ignore-db=
Long_query_time=1
Relay-log=/data/3309/relay_bin
Relay-log-info-file=/data/3309/relay_log.info
Sql_mode=no_engine_substitution,strict_trans_tables
[Mysqld_safe]
Log-error=/data/3309/mysql_err.log
Pid-file=/data/3309/mysql_pid.pid
D-2.1. 3. Create MySQL file (startup script)
#!/bin/bash
############################################################
#this scripts is created by Liuweixinat 2015-06-18
#liuweixin qq:1433203077
############################################################
#init
port=3309
Mysql_user= "Root"
mysql_pwd= "Oracle"
Cmdpath= "/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 "stoping mysql...\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
Sleep2
Function_start_mysql
}
#function_kill_mysql ()
#{
# kill-9 $ (ps-ef | grep ' Bin/mysqld_safe ' | grep ${mysql_port} | awk ' {printf} ')
# kill-9 $ (ps-ef | grep ' Libexec/mysqld ' | grep ${mysql_port} | awk ' {printf} ')
#}
Case $ in
Start
Function_start_mysql;;
Stop
Function_stop_mysql;;
#kill)
# function_kill_mysql;;
Restart
Function_restart_mysql;;
*)
printf "Usage:/data/${port}/mysql {start|stop|restart}\n"
Esac
D-2.1. 4. Start the service
#/data/3309/mysql Start
Note: Here through NETSTAT-LNT 330, there is no way to see the 3309 process
D-2.1. 5. Login 3309 Instance
# mysql-h 127.0.0.1-uroot-p--port=3309
# mysql-uroot-p-s/data/3309/mysql.sock
Note: The new database does not have a password, the direct return can be.
This article from "Technology bo" blog, declined reprint!
MySQL series D-2------MySQL multiple instances add an instance