How to copy the whole database to another server database?
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.
- Open MySQL Workbench
- Create the old server's connection (if you haven't it)
- Create the new server's connection (if you haven't it)
- Go to Server Administration and click Manage Import / Export
- Select old server
- Select all schemas in Export to Disk tab
- In options select Export to Self-Contained File, wait until it finished
- Back to Server Administration and click Manage Import / Export
- Select new server
- Switch to "Import from Disk"
- 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.
To copy a database directly, without doing an export and import first, you can use the MySQL Utilities command mysqdbcopy
:
mysqldbcopy --source=root:root@localhost --destination=root:root@localhost world:world_clone
You can either run the command in a Windows cmd
or the MySQL Utilities Console.