2

I have a Mysql database dump. I want to install it with Hudson via a Shell Script to an external Linux machine.

How can you take a Mysql script and run it inside a database on other machine? I know I can transfer files with sftp and use ssh when accessing another machines manually, but how to automate this all to a simple Shell Script?

1 Answer 1

3
$ mysql -p$pass -u$user -h$otherhost $db < dumpfile

This assumes dumpfile is text from mysqldump, containing raw SQL statements.

It is important that there be no space between -p and the password. (I assume you want automatic login.) If the password does not immediately follow the -p, mysql interprets the option as meaning it should ask interactively for the password, and treats the separate password argument as the DB name.

For this to work, $user must have permission to log in, drop a table, create a table, and insert rows into that table, all as a remote user. MySQL keeps separate remote and local permissions for users, so this is an easy trap to fall into. Because allowing a remote user this much power is a security risk, you may want to use SSL (--ssl* options) with mysql. Otherwise, I don't know that I would allow a remote user to do such things.

1
  • +1: That serves quite well what I am trying to do. Thanks!
    – mico
    Jul 12, 2011 at 10:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .