2
mysql> -u username -p [database] < file.sql

restores database. I do not have a create clause in my dumped file, hence I need to create a database and then restore. I can do this to create.

mysql> create database [database];

Fair enough. Now how can I achieve the above restoration in one line? Is there anyway to restore a database by creating the database before that with a single line of code?

I can certainly live without it, but would be nice to know.. Thanks..

1 Answer 1

5

(echo "create database XYZ; use XYZ;"; cat file.sql) | mysql -u username -p

could do the trick.

Sign up to request clarification or add additional context in comments.

2 Comments

it outputs the given file after the output of the echo command. All together are piped into the mysqlprocess.
This din work for me. I was preferably seeing for mysql solution itself. Something like mysql> -u username -p --create [database] < file.sql or so.. Anyway thanks, I learned something new..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.