バックグラウンドで 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+Cbashスクリプトを終了します。

私も試してみましたが、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 UTC):

エラー履歴、'/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 UTC):

すみません!wait 実行直後にmysqld_safeコマンドがあるという事実を追加するのを忘れました。この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待つ必要があります!プロセスは自分の状態を決して変更しないので(無限ループにある)、コマンドは永遠に待ちます!mysqldmysqlmysqld_safewait

mysqldそのため、プロセスが開始されるのを待つコードを書いています。

おすすめ記事