Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy the whole database to another server database?

I am currently working on a Windows application with a MySQL backend. Now I want to copy the old database structure and data to a new database server.

How can I solve this problem using MySQL workbench?

Thank you!

like image 632
Vinoth Avatar asked Sep 18 '12 07:09

Vinoth


People also ask

How do I copy an entire database?

Expand Databases, right-click the desired database, point to Tasks, and then select Copy Database... If the Welcome to the Copy Database Wizard splash page appears, select Next. Select a Source Server page: Specify the server with the database to move or copy.


2 Answers

  1. Open MySQL Workbench
  2. Create the old server's connection (if you haven't it)
  3. Create the new server's connection (if you haven't it)
  4. Go to Server Administration and click Manage Import / Export
  5. Select old server
  6. Select all schemas in Export to Disk tab
  7. In options select Export to Self-Contained File, wait until it finished
  8. Back to Server Administration and click Manage Import / Export
  9. Select new server
  10. Switch to "Import from Disk"
  11. Click "import from Self-contained File

This is the way with only MySQL Workbech, some times you haven't it installed in new server, like in development to production scenario, in this way you should execute the mysqlimport utility.

like image 82
Alberto León Avatar answered Oct 11 '22 21:10

Alberto León


Using MySQL Workbench [Migration Wizard]

To directly copy a database from one server to another (even a local one) without creating intermediary export/dump files, you can do so within MySQL Workbench using its Migration Wizard. Go to Database --> Migration Wizard.

From there you can select the source and destination connections if you've previously saved them to your Connections list, or you can create a new connection on the fly (be sure to check the box add it to your Connections list).
You'll also choose the database type, or select their generic version (don't remember what it's called) and let it figure out what kind of database servers you have. Generally you can select MySQL for either MySQL or MariaDB databases, as MariaDB is generally designed to be a "binary drop-in replacement" to MySQL.

When it asks you to select which databases, it's my understanding that INFORMATION_SCHEMA is read only, and should not be selected. Otherwise, unless you have specific needs, probably select all the other tables, if you are, say, cloning the server (and perhaps its related website).

From there you'll let MySQL Workbench do its thing. Keep clicking next while it goes through the process of reverse engineering your schema from the old to the new servers, until it finally copies the data over.

There are many points where you can make changes before proceeding. Also you have the option of viewing potential issues and warnings it notes during the process.

When it's done, you'll still need to add users (manually?) for the cloned database. There is probably an automated way to clone the users table over as well, but I don't know about it. You can do this from the command line if nothing else. Since I use this for my local dev, I only have myself to add anyway.

I'm not sure it's any faster using this tool than exporting and importing the databases in the usual manner. But it's sure easier.
This tool is actually designed for more complex migrations between differing kinds of databases (eg PostgressSQL and MySQL) rather than as a general tool for, say, retrieving a copy of your live database down to your local dev server or vice versa.

Under the same menu, there is Database -> Schema Transfer Wizard, which I understood to be used when you need to update to a new server version. I'm not clear specifically the differences between the two tools, or their actual use cases.

Instructions on how to do standard Import / Export operations, in MySQL workbench, the docs are SQL Data Export and Import Wizard, and Table Data Export and Import Wizard.

It would be cool if it were possible to directly import / export between dev and live servers, simply by choosing Connections, rather than saving then reading in dump files.
I think it can be done via the command line though.

like image 36
SherylHohman Avatar answered Oct 11 '22 19:10

SherylHohman