Hi everyone, welcome to another QGIS Tutorial. It’s been a great time here in Indonesia even the weather is a bit harsh. OK, so in this tutorial, I am going to show you how to export or import (whichever term that works for you) shapefile to MySQL database. You may already know that MySQL supports spatial dataset. In other words, we can store spatial dataset in MySQL database, just like PostGIS or SQL Server spatial database. Sounds great right?
Well, the next question would be what do we need to do all these great stuff? First thing first you will need a local or remote MySQL/MariaDB database server. But there is a single problem that we have to deal with. By default, QGIS does not support MySQL Spatial Database. So, we cannot import or export the spatial database from/to MySQL database. Fortunately, there is a special plugin called MySQL Importer that can help us on this matter. MySQL Importer is a QGIS plugin that lets us export our spatial datasets straight away to the MySQL database. You can check their official website here. For me, this is a must-have plugin for every QGIS users.
How to Export Shapefile to MySQL Database on QGIS
Step 1. Install MySQL Importer plugin
Head over the Plugins | Manage and Install Plugin on the QGIS. Then, search for MySQL Importer. Install the plugin from there. In most cases, you will get an error message. You can find the correct way to install MySQL Importer plugin. Read and follow the tutorial carefully and I am pretty sure you will end up with a successful installation.
Step 2. Export Shapefile to MySQL Database
Open MySQL Importer. To do this, go to Database | MySQL Importer | Import Data into MySQL/MariaDB. The new window will open up.
Enter the MySQL Database server IP or hostname, port, username, password and database name. And then browse the shapefile using the tiny button with three dots symbol. Don’t forget to change the CRS as needed. Hit OK and the import process will start.
To open the layer from the MySQL Database, do the following:
That’s it. Thank you for reading this article, I hope you enjoy it and see you in the next tutorials.