Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a bash script that installs mysql for me.

One line, that executes mysqld_safe, makes the script to hang - it won't continue to the following code.

Obviously there's ampersand at line's end, but it won't help, see:

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# 

You can see that only CTRL+C helps to exit, but it exits my entire bash script...

I've also tried using nohup, still didn't help, see:

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# 

Any idea how to force mysqld_safe to run in background?


Edit (May 31, 16:37 UTC):

The error log, '/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

Edit #2 (May 31, 16:46 UTC):

Sorry! I forgot to add that immediately after executing mysqld_safe, there's a wait command. The wait command exists in order to make sure that the daemon has started, so that I'd be able to execute mysql -u root. Please wait, perhaps I'll find a solution.

share|improve this question
    
It is running in the background, but looks like its dieing. What does the error log say? –  jordanm May 31 '13 at 15:12
    
@jordanm: I've added the error log in my first post. –  Dor May 31 '13 at 15:37

2 Answers 2

This looks like you database has gotten corrupted. I'd take a look at his post over on dba.stackexchange.com for steps on what to do next. This looks to be a database issue and nothing to do with your script.

share|improve this answer
    
I'm killing the mysqld process so the result is probably a corrupted InnoDB database. Anyway my script can remove & install the database with a single click so it's not a problem :) –  Dor Jun 1 '13 at 18:51
up vote 0 down vote accepted

OK I got to a solution:

# 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

Explanation: The wait command that was executed immediately after executing mysqld_safe, was waiting for mysqld_safe (which is obvious), but I needed it to wait for mysqld which is initiated by the user mysql! The process mysqld_safe would never change it's state (it's in a never-ending loop), therefore the wait command waits forever!

So I wrote a code that waits for mysqld process to start.

share|improve this answer
    
Why don't you use the stop/start script to bring the DB up and down correctly. Killing it this way is a hack. –  slm Jun 1 '13 at 18:58
    
@sim: you mean service mysql stop ? You're right... I should have used that. Thanks for noting! –  Dor Jun 6 '13 at 23:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.