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 t开发者_StackOverflowhen 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..
(echo "create database XYZ; use XYZ;"; cat file.sql) | mysql -u username -p
could do the trick.
精彩评论