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
- Setup developing environment
- Install NetBeans
- Install & configure SaSS
- Install & configure MAMP
- Install WordPress
- Do other configuration related steps if needed
- Add WordPress theme code (from the old to new environment)
- Export MySQL database (from old environment)
- Import MySQL database (to new environment)
- 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:
- Login to phpMyAdmin tool
- Select the database you want to export
- Select Export tab from right window
- Select Export method, I used Quick
- Select SQL from the Format drop down list
- Press Go
- Save the exported file ja move to the new laptop
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:
- Login to phpMyAdmin tool
- Optional: select the database you want to import in
- Select Import tab from right window
- Select Choose file and find the exported file
- Check the Format is SQL
- Press Go below of the page
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).
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.