Link to home
Start Free TrialLog in
Avatar of NerdsOfTech
NerdsOfTechFlag for United States of America

asked on

Mangento REPLACE sample data database with blank data database via SSH

What SSH commands would I need to dump the blank database to .sql then replace the sample data database with the blank .sql file?
Avatar of ygoutham
ygoutham
Flag of India image

need more info, but from what i understand you want to take MYSQLDUMP of a database structure without the data

mysqldump -d  DB_NAME -u DB_USER  -p  > some_file.sql

if you want to blank out your database then the best option would be to drop the database and recreate it with the blank sql file that you have from above

mysql> drop database DB_NAME;

#mysql -u DB_USER -p  DB_NAME < some_file.sql
Avatar of NerdsOfTech

ASKER

Excellent notion. For clarification purposes lets say the blank data "has" data and lets call it the "simple" database; let's call the sample data "example" database.

Steps:
1. You are saying I could drop the example database
2. Dump the simple database into a .sql file
3. Recreate the simple database to REPLACE the example database

Let me know if this is correct. Thanks!
Steps I would follow:

1.  Dump the example database with the "-d" switch to take only the structure and NO DATA
2. Drop the simple database
3. Recreate the simple database  (we only create the database and it has no tables as of now)
4. Restore the tables in simple database from the .sql file created
Basically I want to erase the example database completely and replace it with the simple database.

Can I dump the example database and "rename" the simple database as the example database?

Is there such a command?
correction:

Basically I want to erase the example database completely and replace it with the simple database.

Can I DELETE the example database and RENAME the simple database as the example database?

Is there such a command?
ok i understood it in the reverse.

you can rename databases

http://dev.mysql.com/doc/refman/5.1/en/rename-database.html

but ideally i would not recommend such a thing.  it is simpler that you dump an empty structure and move it into the database that you want to create (with or without data).  the grant privileges and other things do get hit.  the site (mysql) itself gives a warning that they are discontinuing the syntax. so if the gurus believe that it is a bad option, why get into trouble?
What is the safe way to do this. Both databases have the same structure except the example database has stuff I DONT WANT. Both have same user, password, and privileges.

What is the best approach in your opinion in this case?
drop EXAMPLE, take a dump of SIMPLE, restore the same into EXAMPLE

that should give you the stuff you want and take away the unnecessary ones
more often than we require, we end up with a database that has more junk than useful data.  if you have a clean minimal data from a existing database that you want to use, then ideal would be to take a dump of the current UNWANTED data (store it for any unforeseen requirements) and drop database.

recreate the database with minimal required data and hope that you continue without a hassle.

renaming databases is currently discontinued in the latest versions of mysql. so good luck if you still have an older version which is willing to rename a database from CLI.  that is not a problem either, but as I said earlier, we do not know what problems that we might run into when we do this.  

better to be safe -> take a dump of both databases.  try renaming the SIMPLE -> EXAMPLE. if it works let the setup continue. else drop all databases and have only the one you want.

you would have the .sql files for both the databases in this way. and voila!!! can also create the database with unwanted data, if you so wish.... :-)
Going the best practice route what is the procedure, step by step to:
{code please}

1. dump example to example.sql
2. drop example
3. dump simple to simple.sql
4. create "example" (name is same) using simple.sql
5. drop simple

Thanks!!!
ASKER CERTIFIED SOLUTION
Avatar of ygoutham
ygoutham
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
A+A+Amazing knowledge! Super Job! Thank you.