2

I am logging into my web server remotely using SSH and I'm wondering if there is a way that I can execute an sql script I have residing in a directory on that server in order to create a new database,

The site is a wordpress site and the data in the test database is important for the live site. Does anyone know of how I can execute this script?

2

Because of the other answers did not answer your question completely here are the right answer:

To fire up an sql script via command line you have to execute:

mysql -u [USERNAME] -p < /path/to/sqlscript

[USERNAME] must be the database administrator or another user with sufficient rights to create a database. The password will be asked after execution.

You could find more informations in mysql documentation

2

You can use the following syntax to achieve this from e.g. a bash-script:

mysql -u [user] -p[pass] << EOF
[mysql commands]
EOF
2

You can use the mysqladmin command.

The following command will create a database named 'abcd' from shell.

mysqladmin -u root -p<yourpasswd> create abcd

Please note that there is no space between -p and the password. If you wish to run the command without the password in the command line, you can do it without it, but then it will ask for the password after you hit ENTER.

mysqladmin -u root -p create abcd

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.