I often use Sequel Pro when I’m getting up to speed on the data model for a project or when I just want to debug in a more visual way than with the mysql command-line client. It’s a free OS X application that
lets you inspect and manage MySQL databases. I also find it very useful for making small changes to the data while I develop and test web apps. I recently needed a way to copy a few dozen records from one camp to another. I tried using the “SELECT…INTO OUTFILE”
method but ran into a permissions issue with that approach. Using mysqldump was another option but that seemed like overkill in this case—I only needed to copy a few records from a single table. At this point I found a really neat and helpful feature in Sequel Pro: Copy as SQL INSERT I simply selected the records I wanted to copy and used the “Copy as SQL INSERT” feature. The SQL insert statement I needed was now copied to the system clipboard and easily copied over to the other camp and imported via the mysql command-line client. The Sequel Pro website
describes Bundles which extend the functionality in various ways—including copying data as JSON. Very handy stuff. Many thanks to the developers of this fine software. If you’re on OS X, be sure to give it a try. database
environment mysql tools This post's content Migrating a MySQL database usually requires only few simple steps, but can take quite some time, depending on the amount of data you would like to migrate. The following steps will guide through how to export the MySQL database from the old server, secure it, copy it to the new server, import it successfully and make sure the data is there. Exporting MySQL database to a dump fileOracle provides a utility named mysqldump which allows to easily export the database structure and data to an SQL dump file. Use the following command: mysqldump -u root -p --opt [database name] > [database name].sql Few notes:
Secure the backup fileIn most cases, an organization's data is its most critical asset. Therefore, we do not want database backups laying around in our servers unprotected, as they can mistakenly leak or even worse, get stolen by hackers. Therefore, at the first chance you get, let's compress and encrypt the file and delete the original file. To encrypt the file to a compressed file in Linux operating systems, use this command: zip --encrypt dump.zip db.sql You will be prompted to enter a password before the compression starts. Transfer the backup fileNow that we have an encrypted dump file, let's transfer it over the network to the new server, using SCP: scp /path/to/source-file [email protected]:/path/to/destination-folder/ Import MySQL dump to new serverNow that we have the backup file on the new server, let's decrypt and extract it: unzip -P your-password dump.zip Once the file is imported, remember to delete the dump file both for storage and security reasons. mysql -u root -p newdatabase < /path/to/newdatabase.sql Validate imported data in new serverNow that we have the database imported on the new server, we need a way to make sure that the data is actually there and
we didn't lose anything. SELECT TABLE_NAME, TABLE_ROWS FROM `information_schema`.`tables` WHERE `table_schema` = 'YOUR_DB_NAME'; In addition, we recommend to check for MIN and MAX records of columns in the tables, to make sure the data itself is valid and not only the amount of data. Another export & import optionWe kept this option to the end, as we do not really recommend working with it. mysqldump -u root -pPassword --all-databases | ssh [email protected]_host.host.com 'cat - | mysql -u root -pPassword' Important Notes
Enjoy your new server! How do I copy data from one MySQL database to another?The fastest way to copy a table in MySQL:. Right-click the table you want to copy in Database Explorer and select Duplicate Object.. In the dialog that opens, select the destination db.. Select to copy the table data or structure only.. Specify the name of the new table, and click OK.. How do I transfer data from one database to another?Migrate data from one database to another. Create a source database Connection.. Create a destination database Connection.. Start creating a Flow by selecting Database to database in the Gallery.. Add a new source to destination transformation.. Define the transformation parameters when the source is a database.. How do I copy a table data from one database to another database?Enter the data source, server name and select the authentication method and the source database. Click on Next. Now, enter the destination, server name, authentication method and destination database then click on Next. Select 'Copy data from one or more tables or views' option in the next window and click on Next.
How do I transfer data from one schema to another in MySQL?Right-click on the database name then select "Tasks" > "Export data..." from the object explorer. 4. Provide authentication and select the source from which you want to copy the data; click "Next".
|