mysql 单机多实例脚本启动时候报错
#!/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
[root@localhost 3306]# mysql start
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
配置目录 /data/3306/my.cnf 以及 /data/3306/data (数据文件)
/usr/local/mysql/bin/mysqld_safe --defaults-file=/data/3306/my.cnf 这样启动能够正常启动的。
但是使用脚本启动报错
my.cnf
###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
安装过程学习自:
http://www.linuxidc.com/Linux/2014-07/104508.htm
要执行function_start_mysql,而不是mysqlstart
回复 @JinneyCN:linux和windows之间的不完全兼容。。。解决办法错误分析:因为操作系统是windows,我在windows下编辑的脚本,所以有可能有不可见字符。脚本文件是DOS格式的,即每一行的行尾以来标识,其ASCII码分别是0x0D,0x0A.可以有很多种办法看这个文件是DOS格式的还是UNIX格式的,还是MAC格式的解决方法:回复 @tongcanghai:感谢您的回答。mysqlstart.这里的mysql是放在/data/3306/目录下的启动脚本。使用命令/data/3306/mysqlstart可以启动。如果启动出现/bin/bash^M:badinterpreter:没有那个文件或目录mysqlstart未必会去读取/data/3306/my.cnf版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。