在后台运行 mysqld_safe

在后台运行 mysqld_safe

我有一个为我安装 mysql 的 bash 脚本。

执行的一行使mysqld_safe脚本挂起 - 它不会继续执行以下代码。

显然,行尾有&符号,但这没有帮助,请参阅:

root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# /usr/local/mysql/bin/mysqld_safe --skip-networking --skip-grant-tables --user=mysql --basedir=/usr/local/mysql --ledir=/usr/local/mysql/libexec &
[1] 20131
root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# 130531 17:45:54 mysqld_safe Logging to '/usr/local/mysql/var/dor-desktop.err'.
130531 17:45:54 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
^C
root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# 

你可以看到这只CTRL+C有助于退出,但它退出了我的整个 bash 脚本......

我也尝试过使用nohup,仍然没有帮助,请参阅:

root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# nohup /usr/local/mysql/bin/mysqld_safe --skip-networking --skip-grant-tables --user=mysql --basedir=/usr/local/mysql --ledir=/usr/local/mysql/libexec &
[1] 19751
root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# nohup: ignoring input and appending output to `nohup.out'
^C
[1]+  Exit 1                  nohup /usr/local/mysql/bin/mysqld_safe --skip-networking --skip-grant-tables --user=mysql --basedir=/usr/local/mysql --ledir=/usr/local/mysql/libexec
root@dor-desktop:/home/dor/Documents/LAMP_setup/webs_install# 

知道如何强制mysqld_safe在后台运行吗?


编辑(世界标准时间 5 月 31 日 16:37):

错误日志,'/usr/local/mysql/var/dor-desktop.err'

130531 18:03:55 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
130531 18:03:55 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
130531 18:03:55 [Note] Plugin 'FEDERATED' is disabled.
130531 18:03:55  InnoDB: Initializing buffer pool, size = 8.0M
130531 18:03:55  InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
130531 18:03:55  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
130531 18:03:56  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
130531 18:03:56  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
130531 18:03:56  InnoDB: Started; log sequence number 0 0
130531 18:03:56 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.57-log'  socket: '/usr/local/mysql/mysql.sock'  port: 3306  Source distribution
130531 18:08:41 mysqld_safe mysqld from pid file /usr/local/mysql/var/dor-desktop.pid ended
130531 18:17:09 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
130531 18:17:09 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
130531 18:17:09 [Note] Plugin 'FEDERATED' is disabled.
130531 18:17:09  InnoDB: Initializing buffer pool, size = 8.0M
130531 18:17:09  InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130531 18:17:09  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130531 18:17:09  InnoDB: Started; log sequence number 0 44233
130531 18:17:09 [Note] Recovering after a crash using mysql-bin
130531 18:17:09 [Note] Starting crash recovery...
130531 18:17:09 [Note] Crash recovery finished.
130531 18:17:09 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.57-log'  socket: '/usr/local/mysql/mysql.sock'  port: 3306  Source distribution
130531 18:21:14 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/var
130531 18:21:14 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
130531 18:21:14 [Note] Plugin 'FEDERATED' is disabled.
130531 18:21:14  InnoDB: Initializing buffer pool, size = 8.0M
130531 18:21:14  InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130531 18:21:14  InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130531 18:21:14  InnoDB: Started; log sequence number 0 44233
130531 18:21:14 [Note] Recovering after a crash using mysql-bin
130531 18:21:14 [Note] Starting crash recovery...
130531 18:21:14 [Note] Crash recovery finished.
130531 18:21:14 [Note] /usr/local/mysql/libexec/mysqld: ready for connections.
Version: '5.1.57-log'  socket: '/usr/local/mysql/mysql.sock'  port: 3306  Source distribution

编辑#2(世界标准时间 5 月 31 日 16:46):

对不起!我忘了补充一下,执行mysqld_safe后立即有一个wait 命令。该wait命令的存在是为了确保守护进程已启动,以便我能够执行mysql -u root.请稍等,也许我会找到解决办法。

答案1

好的,我找到了解决方案:

# Wait for the mysqld_safe process to start
while ! [[ "$mysqld_process_pid" =~ ^[0-9]+$ ]]; do
  mysqld_process_pid=$(echo "$(ps -C mysqld -o pid=)" | sed -e 's/^ *//g' -e 's/ *$//g')
  sleep 1
done

解释:执行后立即执行的 wait 命令mysqld_safe正在等待mysqld_safe(这是显而易见的),但我需要它等待mysqld用户发起的mysql!该进程mysqld_safe永远不会改变它的状态(它处于永无休止的循环中),因此该wait命令永远等待!

所以我编写了一段等待mysqld进程启动的代码。

答案2

这看起来您的数据库已损坏。我会在 dba.stackexchange.com 上查看他的帖子,了解下一步该做什么。这看起来是一个数据库问题,与您的脚本无关。

相关内容