3

I wrote a bash script, and here is my problem. The script run for hours, and it never completes. I see the MySQL import process finish, but the script never gets any further. I have tried adding an echo after the MySQL command, but I don't see that echo either. It's like I never get the message that MySQL is complete.

Here is the code for the bash script:

#!/bin/bash
PASSWORD="password"

db="dbName"
file=`date +%Y%m%d`.$db.sql
gunzip $file.gz

mysql -u $USER -p$PASSWORD < $file

 yest= date -d "yesterday 13:00 " '+%Y%m%d'.$db.sql
rm -f $yest

echo Done

update:

logged this import and i see:

       55 Query UNLOCK TABLES
       55 Query /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */
       55 Query /*!40101 SET SQL_MODE=@OLD_SQL_MODE */
       55 Query /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */
       55 Query /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */
       55 Query /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */
       55 Query /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */
       55 Query /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
       55 Query /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */
       55 Quit

as the last command in the logs, which is the last command in the sql file as well.

this is where it hangs...

  • Are you sure gunzip completes? – jobin Apr 29 '14 at 21:02
  • i believe so, because the data is getting pumped into the db and i see the gunzipped sql file in the dir still. – bart2puck Apr 29 '14 at 21:05
  • Does the same thing happen when you execute the mysql command yourself? – Jos Apr 29 '14 at 21:49
2

EDIT: A Better way, just use >> to append to the file.
Note my mistake it's "quit" not ".quit"

mysql probably needs a "quit" command to exit. You might need to append that to the .sql file

#!/bin/bash
USER="user"
PASSWORD="password"
echo "User and Password Set."



db="dbName"
file=`date +%Y%m%d`.$db.sql
gunzip $file.gz
echo "DB File Unzipped"
echo "quit" >> $file    ####  append .quit command to end of file
echo "" >> $file         #### just to make sure there is a return at the end of the previous line
mysql -u $USER -p$PASSWORD < $file

yest= date -d "yesterday 13:00 " '+%Y%m%d'.$db.sql
rm -f $yest

echo Done
  • i understand what you are saying here and think you are on the right track. this brings up another question though. the sql file is the result of mysqldump on another server, there is no human intervention, so how can i add append "quit" to the sql file? – bart2puck Apr 30 '14 at 14:49
  • @bart2puck, I made edits to the above. This should make the changes you need. Let me know if this doesn't work and I will see if I can figure out why. – dboals Apr 30 '14 at 16:13
  • hmm. running into a problem now where, just running in mysql < file.sql never ends...forget about the bash script for now.. – bart2puck May 2 '14 at 17:01
  • What does file.sql look like at the very end of the file? My guess is it is hung up on something. What happens if you just run that command on the command line? – dboals May 2 '14 at 17:03
  • i turned on logging and this query takes a really long time.Query /*!40000 ALTER TABLE ts_uf_audioDescriptiveInfo ENABLE KEYS */ – bart2puck May 2 '14 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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