开发者社区> 问答> 正文

mysql 单机多实例 脚本启动报 ERROR 2002 (HY000)?报错

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

展开
收起
爱吃鱼的程序员 2020-06-08 09:39:35 747 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    要执行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
    2020-06-08 09:39:51
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
搭建4层电商项目架构,实战连接MySQL 立即下载
PolarDB MySQL引擎重磅功能及产品能力盛大发布 立即下载
阿里云企业级自治数据库 RDS 详解 立即下载

相关镜像