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 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?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

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

share|improve this answer

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

mysql -u [user] -p[pass] << EOF
[mysql commands]
EOF
share|improve this answer

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
share|improve this answer

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.