Quick command line MYSQL backup or copy your mysql database

Just a quick note on how to backup or copy your database through the command line.

First thing you need is a sql dump of your database :-

Show Plain Text
Text code
  1. mysqldump --add-drop-table -h <hostname -u <user_name> -p <database_name> > database_name.sql

Now login to your mysql :-

Show Plain Text
Text code
  1. mysql -h <hostname> -u <user_name> -p

Now create your new database :-

Show Plain Text
Text code
  1. create new_database;

Now copy your data to the new database :-

Show Plain Text
Text code
  1. use new_database;
  2. source database_name.sql;

Job done

Filed under: Notes  Tags: Mysql

0 Responses to “Quick command line MYSQL backup or copy your mysql database”

Sorry, comments have been closed for this post.
(default) 11 queries took 9 ms
NrQueryErrorAffectedNum. rowsTook (ms)
1DESCRIBE `posts`17171
2DESCRIBE `comments`11111
3DESCRIBE `tags`221
4DESCRIBE `categories`221
5DESCRIBE `posts_tags`221
6DESCRIBE `categories_posts`222
7SELECT `Post`.`id`, `Post`.`url`, `Post`.`title`, `Post`.`icon`, `Post`.`metadesc`, `Post`.`metakeys`, `Post`.`categories`, `Post`.`tease`, `Post`.`body`, `Post`.`private_body`, `Post`.`created`, `Post`.`modified`, `Post`.`status`, `Post`.`allow_comments`, `Post`.`tags`, `Post`.`hitcount`, `Post`.`hitcount_rss` FROM `posts` AS `Post` WHERE `Post`.`url` = 'quick-command-line-mysql-backup-or-copy-your-mysql-database' LIMIT 1111
8SELECT `Comment`.`id`, `Comment`.`post_id`, `Comment`.`body`, `Comment`.`author`, `Comment`.`url`, `Comment`.`email`, `Comment`.`ip`, `Comment`.`status`, `Comment`.`junk_score`, `Comment`.`created`, `Comment`.`modified` FROM `comments` AS `Comment` WHERE `Comment`.`status` = 2 AND `Comment`.`post_id` = (88) 000
9SELECT `Tag`.`id`, `Tag`.`tag`, `PostsTag`.`post_id`, `PostsTag`.`tag_id` FROM `tags` AS `Tag` JOIN `posts_tags` AS `PostsTag` ON (`PostsTag`.`post_id` = 88 AND `PostsTag`.`tag_id` = `Tag`.`id`) 110
10SELECT `Category`.`id`, `Category`.`category`, `CategoriesPost`.`post_id`, `CategoriesPost`.`category_id` FROM `categories` AS `Category` JOIN `categories_posts` AS `CategoriesPost` ON (`CategoriesPost`.`post_id` = 88 AND `CategoriesPost`.`category_id` = `Category`.`id`) 110
11UPDATE `posts` AS `Post` SET `Post`.`hitcount` = Post.hitcount + 1 WHERE `Post`.`id` = 8811