Portal Home > Knowledgebase > Articles Database > mysqldump import issues
mysqldump import issues
Posted by rwssoccer1, 01-11-2011, 02:24 PM |
Im setting up a cron job that will automatically backup my personal server and upload it to a backup server. Everything is working but i have a question about restoring the databases. If i have a database that is already created the import of the dump works fine EX: mysql -u "username -p"password" "databasename" < database.sql
The problem is when the database doesnt exist i get an error saying exactly that, the database doesnt exist. If i just do a restore without specifying the database i assume this will overwrite everything in MySQL. All i want to do is restore the database that is not there without overwriting anyhting.
thanks
|
Posted by asciiDigital, 01-11-2011, 02:37 PM |
Create the database first, then import the sql file. I don't understand the problem.
|
Posted by rwssoccer1, 01-11-2011, 02:54 PM |
is there any way to do it without creating the database...thats the question
|
Posted by squirrelhost, 01-11-2011, 03:09 PM |
iif you want 'create database ...' in the sql dump
run mysqldump with the flag
--databases
this will produce your dump with a 'create database ...' line
e.g.
mysqldump -u username -ppassword databasename --databases > dump.sql
|
Posted by rwssoccer1, 01-11-2011, 03:13 PM |
if i do a restore with mysql -u "username -p"password" < database.sql will it overwite everyhting since i didnt specify a database or will it ony wtite whats not there already?
|
Posted by squirrelhost, 01-11-2011, 03:17 PM |
If the database doesn't exist, it create it and writes your data, which is what restore does. The dump will have a line (for each table) like:
DROP TABLE IF EXISTS `tablename`;
then it does the rest.
|
Add to Favourites Print this Article
Also Read