Showing posts with label restore. Show all posts
Showing posts with label restore. Show all posts

Monday, June 18, 2012

MySQL : Use mysqldump to get the schema only


Dumping the database structure for all tables with no data


Add the -d flag to signify that no data should be included in the output like so, where "mydatabase" is the name of the database to dump, and "someuser" is the login name used to connect to the database
mysqldump -d -u someuser -p mydatabase

Dumping the database structure for one table with no data

mysqldump -d -u someuser -p mydatabase products

Dumping the database structure for several table with no data

mysqldump -d -u someuser -p mydatabase products categories users

Dumping the structure to a file

mysqldump -d -u someuser -p mydatabase > mydatabase.sql

Restore the structure file to mysql

mysql -u someuser -p anotherdatabase < mydatabase.sql

Tuesday, May 8, 2012

Mysql: Dump & Restore Database

Mysql Dump Syntax/Command

We use mysqldump command to do database backup

# mysqldump -uroot -p --databases filename > backupname.sql

eg: mysqldump -uroot -p --databases staff > staff130509.sql

Then, to dump back/restore the backup database to server, use this command:

#mysql -uroot -p < staff130509.sql

But, for UTF8 case, use this command:

#mysql -uroot -p --default-character-set=utf8 < staff130509.sql

Then to check the current process list in mysql server:

#mysql -uroot -pPASSWORD
mysql> show processlist;


To show processlist with out all the sleeping processes...
mysql> \P grep -v Sleep