mysql 单机多实例
/data
------3306
---------- data
-------3307
-----------data
###3306
# The following options will be passed to all MySQL clients
[client]
#password      = your_password
port            = 3306
socket          = /data/3306/mysql.sock# Here follows entries for some specific programs# The MySQL server
[mysqld]
port            = 3306
socket          = /data/3306/mysql.sock
datadir         = /data/3306/data
long_query_time = 1
#log-error     = /data/3306/error.log
#log-slow-queries = /data/3306/slow.log
pid-file        = /data/3306/mysql.pid
#log-bin  = /data/3306/mysql-bin
relay-log-info-file = /data/3306/relay-log.info
server-id = 1
log-error=/data/3306/mysql_3306.error
pid-file=/data/3306/mysqld.pid-file
user            = mysql
###3307
# The following options will be passed to all MySQL clients
[client]
#password      = your_password
port            = 3307
socket          = /data/3307/mysql.sock# Here follows entries for some specific programs# The MySQL server
[mysqld]
port            = 3307
socket          = /data/3307/mysql.sock
datadir         = /data/3307/data
long_query_time = 1
#log-error     = /data/3307/error.log
#log-slow-queries = /data/3307/slow.log
pid-file        = /data/3307/mysql.pid
#log-bin  = /data/3307/mysql-bin
relay-log-info-file = /data/3307/relay-log.info
server-id = 3
log-error=/data/3307/mysql_3307.error
pid-file=/data/3307/mysqld.pid启动脚本#!/bin/sh
# This is an interactive program, we needthe current locale 
[ -f /etc/profile.d/lang.sh ] && . /etc/profile.d/lang.sh 
# We can't Japanese on normal console atboot time, so force. 
if [ "$LANG" = "ja" -o "$LANG" = "ja_JP.eucJP" ]; then
   if [ "$TERM" = "linux" ] ; then
       LANG=C 
   fi
fi
    
# Source function library. 
. /etc/init.d/functions
#init
port=3306
mysql_user="root"
mysql_pwd="123456"
CmdPath="/application/mysql/bin"
mysql_sock="/data/${port}/mysql.sock"
#startup function
function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      ${CmdPath}/mysqld_safe --defaults-file=/data/${port}/my.cnf --ledir=${CmdPath} 2>&1 > /dev/null &
      sleep 2
    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"
       ${CmdPath}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S $mysql_sock shutdown
       sleep 2
   fi
}
#restart function
function_restart_mysql()
{
    printf "Restarting 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
;;
status)
    status mysqld
;;
*)
    printf "Usage: /data/${port}/mysql {start|stop|restart|status}\n"
esac
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf  这样启动没有问题
但是 如果用上面的脚本启动就会出错呢。
[root@localhost 3306]# mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.so