Executa o mysqld_safe no background

0

Eu tenho um script bash que instala o mysql para mim.

Uma linha, que executa mysqld_safe , faz com que o script seja interrompido - não continuará no código a seguir.

Obviamente, há um e comercial no final da linha, mas não vai ajudar, veja:

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# 

Você pode ver que apenas CTRL+C ajuda a sair, mas sai do meu script bash inteiro ...

Eu também tentei usar nohup , ainda não ajudei, veja:

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# 

Alguma ideia de como forçar o mysqld_safe a ser executado em segundo plano?

Editar (31 de maio de 16:37 UTC):

O log de erros, '/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

Editar # 2 (31 de maio, 16:46 UTC):

Desculpe! Esqueci de adicionar isso imediatamente após a execução do mysqld_safe, há um comando wait . O comando wait existe para garantir que o daemon tenha iniciado, para que eu possa executar mysql -u root . Por favor, espere, talvez eu encontre uma solução.

    
por Dor 31.05.2013 / 16:51

2 respostas

2

OK, cheguei a uma solução:

# 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

Explicação: O comando wait que foi executado imediatamente após a execução de mysqld_safe , estava esperando por mysqld_safe (o que é óbvio), mas eu precisava esperar por mysqld que é iniciado pelo usuário mysql ! O processo mysqld_safe nunca mudaria seu estado (está em um loop que nunca termina), portanto o comando wait aguarda para sempre!

Então eu escrevi um código que espera por mysqld processo para iniciar.

    
por 01.06.2013 / 20:49
0

Isso parece que seu banco de dados ficou corrompido. Eu daria uma olhada no post dele em dba.stackexchange.com para saber o que fazer em seguida. Isso parece ser um problema de banco de dados e nada a ver com seu script.

por 01.06.2013 / 14:22