How to Export and Import MySQL Database

MAMP and my Mac


This is a short guide for how to export and import MySQL database. My problem was that I got a new laptop and I was developing a WordPress Theme on my old laptop. I needed to setup the whole WordPress developing environment for my new Mac and find out, how can I transfer the developed work from Linux Ubuntu environment to new one. The whole process was quite easy, but I made few mistakes which I will tell you soon.

All I needed to care about was the code of the WordPress theme, database and pictures. Of course, the environment needed to set up at first as it was on the old laptop.


The steps are

  1. Setup developing environment
    • Install NetBeans
    • Install & configure SaSS
    • Install & configure MAMP
  2. Install WordPress
  3. Do other configuration related steps if needed
  4. Add WordPress theme code (from the old to new environment)
  5. Export MySQL database (from old environment)
  6. Import MySQL database (to new environment)
  7. Move pictures to WordPress (from old to new)

Export MySQL Database

Exporting the database from the old environment can be done in several ways. I did it from myPHPAdmin tool.  The steps are:

  1. Login to phpMyAdmin tool
  2. Select the database you want to export
  3. Select Export tab from right window
  4. Select Export method, I used Quick
  5. Select SQL from the Format drop down list
  6. Press Go
  7. Save the exported file ja move to the new laptop

export MySQL database

 

Import MySQL Database

Importing database needs more thinking. First you have to decide, do you import in existing database or do you just import the database as a new one. What comes to WordPress, the database name has to be same as it was in the old environment, otherwise it’s not working.

The steps are:

  1. Login to phpMyAdmin tool
  2. Optional: select the database you want to import in
  3. Select Import tab from right window
  4. Select Choose file and find the exported file
  5. Check the Format is SQL
  6. Press Go below of the page

Import mySQL database

Problems During the Process

I faced couple of problems during the database transfer process. The first one was that I gave a new better name for my project and while I did WordPress installation, I also created a database with a new name. Obviously, the configuration didn’t work at all after database import.

I fixed it so that I imported the old database with the old name and after that I removed the new database and change the DB_NAME definition from wp-confing.php file.

The other problem was to get connected with the database, but I figured out that if I use MAMP tool for my project, there are specific database configuration values I have to use in wp-config.php file (see the picture below).

MAMP configuration

 

When I need to do this again, I have to figure out also, what is the best order to do the whole process so that it will go more smoothly. This is a good addition to my coding journey. Remember, there are a several ways to do import and export mySQL database and this is not a complete guidance. I’ll hope writing it down can help me on next time.

Leave a Reply

Your email address will not be published. Required fields are marked *