Percona-server 在 /etc/init.d/mysql 启动时超时

ks_*_*010 6 mysql percona

每次我启动mysql,使用/etc/init.d/mysql start 或service mysql start 时,总是超时。

 * Starting MySQL (Percona Server) database server mysqld                   [fail] 
Run Code Online (Sandbox Code Playgroud)

但是,我可以进入mysql。只是想知道安装是否有问题,因为它一直发生,而不是一次性错误。

mysql-error.log 显示:

121214 11:25:56 mysqld_safe Starting mysqld daemon with databases from /data/mysql/
121214 11:25:56 [Note] Plugin 'FEDERATED' is disabled.
121214 11:25:56 InnoDB: The InnoDB memory heap is disabled
121214 11:25:56 InnoDB: Mutexes and rw_locks use GCC atomic builtins
121214 11:25:56 InnoDB: Compressed tables use zlib 1.2.3
121214 11:25:56 InnoDB: Using Linux native AIO
121214 11:25:56 InnoDB: Initializing buffer pool, size = 14.0G
121214 11:25:58 InnoDB: Completed initialization of buffer pool
121214 11:26:01  InnoDB: Waiting for the background threads to start
121214 11:26:02 Percona XtraDB (http://www.percona.com) 1.1.8-rel29.2 started; log sequence number 9333955393950
121214 11:26:02 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
121214 11:26:02 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
121214 11:26:02 [Note] Server socket created on IP: '0.0.0.0'.
121214 11:26:02 [Note] Slave SQL thread initialized, starting replication in log 'mysql-bin.005163' at position 624540946, relay log '/data/mysql/mysql-relay-bin.000043' position: 624541092
121214 11:26:02 [Note] Slave I/O thread: connected to master 'repl@10.8.25.111:3306',replication started in log 'mysql-bin.005180' at position 823447620
121214 11:26:02 [Note] Event Scheduler: Loaded 0 events
121214 11:26:02 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.5.28-29.2-log'  socket: '/data/mysql/mysql.sock'  port: 3306  Percona Server (GPL), Release 29.2
Run Code Online (Sandbox Code Playgroud)

Rol*_*DBA 3

错误日志的显示看起来很正常

套接字文件已创建 MySQL 复制已开始正常 /usr/sbin/mysqld: ready for connections.显示

特别是既然你看到了/usr/sbin/mysqld: ready for connections.,你应该能够连接到 mysql,正如你刚才所说的那样。

你的 mysqld 进程没问题。

该错误可能来自/etc/init.d/mysql但不是在 mysqld 完成它需要做的所有其他事情之前。

如果你往里面看/etc/init.d/mysql有两条线

[root@***** init.d]$ cat mysql | grep -n "&" | grep "pid-file"
313:      $manager --user=$user --pid-file=$pid_file >/dev/null 2>&1 &
327:      $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
Run Code Online (Sandbox Code Playgroud)

如果/etc/init.d/mysql超时的话,肯定发生在这两行之后。

这是检查 pid 文件的代码

wait_for_pid () {
  verb="$1"
  manager_pid="$2"  # process ID of the program operating on the pid-file
  i=0
  avoid_race_condition="by checking again"
  while test $i -ne $service_startup_timeout ; do

    case "$verb" in
      'created')
        # wait for a PID-file to pop into existence.
        test -s $pid_file && i='' && break
        ;;
      'removed')
        # wait for this PID-file to disappear
        test ! -s $pid_file && i='' && break
        ;;
      *)
        echo "wait_for_pid () usage: wait_for_pid created|removed manager_pid"
        exit 1
        ;;
    esac

    # if manager isn't running, then pid-file will never be updated
    if test -n "$manager_pid"; then
      if kill -0 "$manager_pid" 2>/dev/null; then
        :  # the manager still runs
      else
        # The manager may have exited between the last pid-file check and now.
        if test -n "$avoid_race_condition"; then
          avoid_race_condition=""
          continue  # Check again.
        fi

        # there's nothing that will affect the file.
        log_failure_msg "Manager of pid-file quit without updating file."
        return 1  # not waiting any more.
      fi
    fi

    echo $echo_n ".$echo_c"
    i=`expr $i + 1`
    sleep 1
  done

  if test -z "$i" ; then
    log_success_msg
    return 0
  else
    log_failure_msg
    return 1
  fi
}
Run Code Online (Sandbox Code Playgroud)

wait_for_pid()在 mysqld_safe 启动后调用

  # Give extra arguments to mysqld with the my.cnf file. This script
  # may be overwritten at next upgrade.
  pid_file=$server_pid_file
  $bindir/mysqld_safe --datadir=$datadir --pid-file=$server_pid_file $other_args >/dev/null 2>&1 &
  wait_for_pid created $!; return_value=$?
Run Code Online (Sandbox Code Playgroud)

在最坏的情况下,mysqld 在没有 pid 文件的情况下运行。鉴于此,service mysql stop可能/etc/init.d/mysql stop无法正常工作,因为它检查 pid 文件以了解 mysqld 的进程 ID。

如果没有 pid 文件,关闭 mysqld 的正确方法是

# mysqladmin -uroot -h127.0.0.1 --protocol=tcp -p shutdown
Run Code Online (Sandbox Code Playgroud)

警告

这并不是一种局部现象。我也曾在标准 MySQL 二进制文件中看到过这种情况。