最近想把公司的mysql5.5.43迁到mariadb10.0.21上,就在测试环境上搞了一把,具体步骤就不谈了,还是蛮简单的~但是到最后启动mariadb的时候踩到坑了~
具体情况如下:
从启动界面来看MariaDB启动不起?!!查看进程看下:
发现mysql进程已经起来了,但是不知道什么原因给hang住了,不停的循环,再查看我的日志和端口
150924 16:57:51 mysqld_safe mysqld from pid file /data/mysql/data/mariadb.pid ended
150924 16:57:54 mysqld_safe Starting mysqld daemon with databases from /data/mysql/data
150924 16:57:54 [Note] /usr/sbin/mysqld (mysqld 10.0.21-MariaDB-log) starting as process 11356 ...
150924 16:57:54 [Note] InnoDB: Using mutexes to ref count buffer pool pages
150924 16:57:54 [Note] InnoDB: The InnoDB memory heap is disabled
150924 16:57:54 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
150924 16:57:54 [Note] InnoDB: Memory barrier is not used
150924 16:57:54 [Note] InnoDB: Compressed tables use zlib 1.2.3
150924 16:57:54 [Note] InnoDB: Using Linux native AIO
150924 16:57:54 [Note] InnoDB: Using CPU crc32 instructions
150924 16:57:54 [Note] InnoDB: Initializing buffer pool, size = 128.0M
150924 16:57:54 [Note] InnoDB: Completed initialization of buffer pool
150924 16:57:54 [Note] InnoDB: Highest supported file format is Barracuda.
150924 16:57:54 [Note] InnoDB: 128 rollback segment(s) are active.
150924 16:57:54 [Note] InnoDB: Waiting for purge to start
150924 16:57:54 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.25-73.1 started; log sequence number 1616817
150924 16:57:54 [Note] Plugin 'FEEDBACK' is disabled.
150924 16:57:54 [Note] Server socket created on IP: '::'.
150924 16:57:54 [Warning] 'user' entry 'root@mariadb' ignored in --skip-name-resolve mode.
150924 16:57:54 [Warning] 'proxies_priv' entry '@% root@mariadb' ignored in --skip-name-resolve mode.
150924 16:57:54 [Note] Event Scheduler: Loaded 0 events
150924 16:57:54 [Note] /usr/sbin/mysqld: ready for connections.
Version: '10.0.21-MariaDB-log' socket: '/data/mysql/mysql.sock' port: 3306 MariaDB Server
150924 16:57:54 [Note] Event Scheduler: scheduler thread started with id 2
连接数据库什么的都是正常的~这样的话就把疑点转移到了/etc/init.d/mysql启动脚本上了,到底是什么原因将启动进程循环的呢?
查看MariaDB10.0.21的mysql脚本发现在启动的时候会调用函数wait_for_ready
case "$mode" in
'start')
# Start daemon
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $basedir
echo $echo_n "Starting MySQL"
if test -x $bindir/mysqld_safe
then
# Give extra arguments to mysqld with the my.cnf file. This script
# may be overwritten at next upgrade.
$bindir/mysqld_safe --datadir="$datadir" --pid-file="$mysqld_pid_file_path" $other_args >/dev/null 2>&1 &
wait_for_ready; return_value=$?
# Make lock for RedHat / SuSE
if test -w "$lockdir"
then
touch "$lock_file_path"
fi
exit $return_value
else
log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
fi
;;
然后再查看wait_for_ready函数咋写的呢?
wait_for_ready () {
i=0
while test $i -ne $service_startup_timeout ; do
i=0
while test $i -ne $service_startup_timeout ; do
if $bindir/mysqladmin ping >/dev/null 2>&1; then
log_success_msg
return 0
elif kill -0 $! 2>/dev/null ; then
: # mysqld_safe is still running
else
# mysqld_safe is no longer running, abort the wait loop
break
fi
echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1
done
log_failure_msg
return 1
}
看到只有当mysqladmin ping命令通过的时候才会返回success,其他情况只会不停的循环.然后900秒后报错退出,但是mysql实际上是已经起来了的。
知道了原因,这里面有两种解决方法
1)在/etc/my.cnf中设置mysqladmin的用户名,密码和socket路径
2)修改mysql启动脚本
这里我采用的是修改mysql启动脚本,怕密码泄露啊!参照mysql5.5中的check方式,check一下pid文件就ok了
wait_for_ready () {
i=0
while test $i -ne $service_startup_timeout ; do
#if $bindir/mysqladmin ping >/dev/null 2>&1; then
if test -e $mysqld_pid_file_path;then
log_success_msg
return 0
elif kill -0 $! 2>/dev/null ; then
: # mysqld_safe is still running
else
# mysqld_safe is no longer running, abort the wait loop
break
fi
echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1
done
log_failure_msg
return 1
}
然后启动搞定!