InfoHeap
Tech
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

Wordpress Mysql Query tutorials

  • How to delete orphan wordpress wp_postmeta rows
  • Mysql query to find all yoast meta description
  • Query to find recently modified posts in Wordpress
  • Wordpress - an approach to bulk add tags to posts
  • Wordpress - query to dump all categories
  • Wordpress - query to dump all posts with featured image
  • Wordpress - query to dump all tags
  • Wordpress - query to find all posts for a category
  • Wordpress - query to find term_taxonomy_id from category name
  • Wordpress - query to find term_taxonomy_id from tag name
  • Wordpress mysql query to get all custom keys and values for a post
  • Wordpress mysql query to get all posts with a missing custom field
  • Wordpress mysql query to get all posts with a specific custom field
  • migrate multiple mysql databases using mysqldump on Linux
 
  • Home
  • > Tutorials
  • > Wordpress
  • > Wordpress Mysql Queries

migrate multiple mysql databases using mysqldump on Linux

By admin | Last updated on Mar 20, 2016

Sometimes we need to migrate all mysql databases to a new machine. This can be the case when you are migrating your multiple wordpress blogs to a new machine on Amazon EC2. Recently I had to do this when I migrated to VPC. Here are quick instructions to migrate all databases on Ubuntu (14.04.2 LTS) Linux using mysqldump (Ver 10.13):

mysqldump all databases

Use mysqldump to dump all your databses to a file

$ mysqldump -u root --password=DB_PASSWORD --all-databases > all_dbs.txt

Note that –all-databases is used to specify all databases. This will not include mysql internal databases information_schema, performance_schema, etc. It will include mysql database though. That will mean all your users will also be migrated.
In case your database is on a remote machine, you can also use ssh to run mysqldump remotely and get data on current local machine.

$ ssh HOSTNAME mysqldump -u root --password=DB_PASSWORD --all-databases > all_dbs.txt

To confirm what databases got dumped to the file, run the following command:

$ grep "^CREATE DATABASE" all_dbs.txt
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bdname1` /*!40100 DEFAULT CHARACTER SET utf8 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bdname2` /*!40100 DEFAULT CHARACTER SET utf8 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/ `bdname3` /*!40100 DEFAULT CHARACTER SET latin1 */;
...

Note that for mysql database CREATE DATABASE statement would not be present. Also note the present of “DROP TABLE IF EXISTS”. This will ensure all tables are overwritten.

$ grep "^DROP TABLE IF EXISTS" all_dbs.txt
DROP TABLE IF EXISTS `wp_commentmeta`;
DROP TABLE IF EXISTS `wp_comments`;
...

Create databases using mysql

Assuming the new machine mysql does not have any db created, run the following to create all these databases on new mysql machine.

$ cat all_dbs.txt | mysql -u root --password=DB_PASSWORD

This will create all the dbs. You can run the following command to display the names of all created databases:

$ mysql -u root --password=DB_PASSWORD -e "show databases;"

Suggested posts:

  1. Python filter vs ifilter
  2. Using Google analytics SDK v2 for android app real time tracking
  3. Display keys added to ssh-agent using ssh-add
  4. SVG – beginner tutorial
  5. How to kill unresponsive ssh session using escape sequence
  6. How to fix a broken sudoers file on AWS/EC2 Linux
  7. Git – rename local branch
  8. How to install mysql 5.7 on Amazon Linux 2
Share this article: share on facebook share on linkedin tweet this submit to reddit
Posted in Tutorials | Tagged Linux, Tutorials, Wordpress, Wordpress Mysql Queries
  • Browse content
  • Article Topics
  • Article archives
  • Contact Us
Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | Company results | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries | InfoHeap Money

Copyright © 2025 InfoHeap.

Powered by WordPress