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
/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
解决方案 »
- MySql存储过程可以实现这样的功能不?
- mysql数据库的奇怪问题,大家mysql是否可能实现。
- MySQL如何查询数据插入时间?
- 求助。。。select count 的赋值问题
- 请问如何将MYSQL一个表中所有小于最大ID的不存在ID找出来
- 前两天装了一个开源的项目建了一堆表 用外建关联在一起删不了??
- 怎么解决mysql中,当有中文和英文的字符串需要比较相等时,不能区分大小写!
- 请教两个SQL查询问题,急!先谢了
- 有会用pgAdminII的没有?
- 数据库出现#1044错误如何解决
- 启动tomcat后,只要有数据操作mysql服务就自动关闭?
- MySQL 中如何根据表 ID 中隐藏的时间戳按天进行分区?
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)