Restoring Database from Command Line


I’m finding myself having to restore a lot of older MySQL databases. It’s getting a bit tedious: (1) finding the DB file, (2) manually creating the database in Siteworx, (3) applying permissions, and (4) going back to command line and executing the restore command. To automate this, I’m trying to write a bash script (which I’d be happy to share here once it’s complete) that accomplishes all of these tasks.

The script will take two arguments: (1) datafile name, (2) the future database name that will hold the restored data.

Everything has been going well thus far, but I’ve ran into a bit of an issue. How does Siteworx create a new database? I’ve tried using existing MySQL users that exist in Siteworx, but it does not appear that they have CREATE DATABASE privileges. With what user does it execute a CREATE DATABASE command? How might I be able to create a new database and apply permissions via command line? I’ve tried running mysql -u root -p, but then realized that I don’t have my MySQL root password and don’t even remember ever having to configure this upon installation of Interworx.

So: how can I create a database and grant a specific MySQL user privileges from command line, in a way that matches the method Siteworx creates DBs and users? I want to make sure that these two things line up.

Thanks much. :cool:

probably the iworx user. But you should be fine using the root user to create the databases.

Gotcha. How does Interworx set the root MySQL password? I don’t even remember configuring this.

Iworx sets its own user’s passwords at setup time. You can read them by doing this:

 grep dsn ~iworx/iworx.ini 

Hi there,

Alright I have this line that I’m working with (bash programming):

mysql -u username -pHASH ${args[1]} < /home/site/backups/site.${args[0]}.sql

I get this error on that line:

./ line 51: syntax error near unexpected token `newline'
./ line 51: `mysql -u username -pHASH ${args[1]} < '

Any ideas?