Tech Tips on Computers, Internet, Blogging, Web Development, Social Media, Android and more

Full width home advertisement

Post Page Advertisement [Top]

phpmyadmin-export-import-single-table
There may be times when you need to export data from a single table and import into a single table in an existing database using phpMyAdmin. In this post, we shall discuss how to export data from a single table and import into single table using phpMyAdmin?

For better understanding, here is a scenario when such an activity may be required. 

So, there is this WordPress website we have, and the theme had to be customized. Since we did not want to disrupt the live site, we took a backup and installed the copy on a development system to further customize the site. During the customization process, we ran into some issues. And to isolate the problem, we disabled some plugins to check if the plugins were interfering with the website issue. 

The problem was, we were using a WordPress plugin called "Post Views Counter" to display views on each post. During this process of troubleshooting as described above, we had also disabled the "Post Views Counter" plugin (or may even have deleted it from the plugins page in WordPress) . Later when we re-installed /re-enabled the plugin, we found the stats have been reset. The post views were all zeros. And we wanted to retain the values. 

After the required customization was done, we needed to bring the stats of "Post Views Counter" from the live site to the development site, before we upload on the live server. Note: there could have been another way to do this, but we did not want to take a risk. More on this described at the end of this post.

So here is what we did: to export data from a single table and import into single table using phpMyAdmin.

How to export data from a single table using phpMyAdmin?

To backup only a particular table in phpMyAdmin, click on the particular table and click Export. This will export only the table and not the entire database. 

Steps to export data from a single table using phpMyAdmin

  • Log in to phpMyAdmin
  • Click on the particular table from the left sidebar (ngk_post_views in this case)
  • Click Export 
  • This will export only the table (ngk_post_views in this case) in .sql file
phpmyadmin-export-single-table-data


Now that we have the backup of the particular table (ngk_post_views in this case), we needed to restore this on the development server.

How to import data into a single table using phpMyAdmin?


To import data from a single table using phpMyAdmin, the process is the same as importing database. BUT, the table you are importing should not exist. Otherwise, phpMyAdmin will throw an error.

phpmyadmin-imported-table-already-exists


Steps to import data into a single table using phpMyAdmin:
  • Log in to phpMyAdmin
  • Back up the entire database (very important) -and save a copy just in case.
  • Click on the database
  • Then select the table we intent to import, and click drop (table)
    This will remove the table from the database -  as we are going to import one. 
phpmyadmin-drop-table

  • Then select the database again, just in case it is not selected
  • Click on import and select the backup file of the table downloaded from the live server
phpmyadmin-import-data-into-single-table

  • If every thing goes well, the import should success (unless there are other issues, which we did not encounter)
phpmyadmin-import-data-into-single-table_success

  • We clicked on the table and checked the values and the counts were restored.
  • Viewed the posts on the site's front end, and we could see the counters restored.
Now that the post view counts have been restored, we migrated the database to the live server. 

By the way, to upload your WordPress website to live server,  you can use plugins like "Duplicator". Here is a previous post on -How to use "Duplicator – WordPress Migration Plugin" to migrate development site to live site?

As mentioned above, this could have been achieved in another way.

We could have "dropped" the post views table from phpMyAdmin of the development system and then exported the database. When this is imported on the live server, the post views table on the live server database is expected to be as it is. Ensure backups are taken before attempting any of the examples in this post, and at your own risk.





3 comments:

Bottom Ad [Post Page]