Hello everyone, welcome to my GIS website. QGIS is an extensible GIS software. We can add more features and functionality to QGIS by installing some Python plugins. These plugins are available from the online repository. We can easily search, download and install this plugin from QGIS. I was kindly interested with the MySQL Importer plugin. With this plugin, it will be possible to import the spatial data to the MySQL database using the ogr2ogr tool. But, this plugin requires the MySQL Python extension installed on our system. Because if you don’t have it, you will end up with the following error.
Let’s start over
Install MySQL Importer Plugin
Go to Plugin | Manage and Install Plugin. The plugin window will open up. Type mysql importer or scroll down until you find the MySQL Importer.
Click Install to start the installation process. On my first attempt, I got the following error
ModuleNotFoundError: No module named ‘MySQLdb’
Here is the screenshot of the error that I got.
How to Fix it?
If you have the same problem, we need to install MySQLclient in our Pyhon directory. In this case, we are going to install the mysqlclient package in the following directory:
C:\Program Files\QGIS 3.4\apps\Python37\Lib\site-packages
First, download the mysqlclient package from this link below:
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient
Scroll down until you find the following section
Choose the version that matches your Python version and system architecture. Next, extract the .whl file using 7z. You can download 7z from this link. After extract, you will have several files and folders.
Simply copy all the files and folders into the Python directory. In this case:
C:\Program Files\QGIS 3.4\apps\Python37\Lib\site-packages
Now, repeat the MySQL Importer installation step. If the installation is successful, you will see the MySQL Importer menu appear under the Database menu.
Now, you can start to import your GIS dataset to your MySQL Server using this MySQL Importer tool.
Paer
January 18, 2020It does not work after copy paste.
Roy
January 22, 2020Worked for me. Downloaded mysqlclient-1.4.6-cp37-cp37m-win_amd64.whl , extracted it with 7-Zip and copied & pasted it to C:\Program Files\QGIS 3.4\apps\Python37\Lib\site-packages.
After restarting QGIS, the MySQL Importer can be installed.
Leo
April 29, 2020Hello for me also, it doesn’t work for QGis 3.10. have you succeeded since or not?
Thank for your answer, this will help me a lot.
Angel
March 20, 2020Muy buen aporte, muchas gracias amigo!!
Luis Marquez
March 30, 2020Thank a lots worked at 1st tey
Abmelech Mureithi
December 8, 2020The instructions are easy to follow but I had an issue I don’t seem to have the two files rather I have the 2 folders after extracting, what could be the problem?
Daniel
April 2, 2021Thanks much for this helpful article!
IOnut
November 20, 2021Works for
Qgis 3.16.13 / Python 3.9 /
Plugin: MySQL Importer Ver 0.7.3
Thanks
Fernando Aquilini
March 14, 2023Perfeito, funcionou perfeitamente aqui para mim!! Muito obrigado!!
HappyLion
April 21, 2023Okay, on mac (12.6.3 monteray) this was a hassle with Python 3.9.6 and QGIS 3.31… so I did the following, which is similar to the windows method.
Make sure you have Brew updated, and Python too I guess.
Install MySQL with ‘brew install mysql’ – I have version: Ver 8.0.32 for macos12.6 on x86_64 (Homebrew)
Install mysqlclient using ‘pip install mysqlclient’ or in my case i had to use ‘pip3 install mysqlclient’ – the version and installation path is: mysqlclient in /Users//Library/Python/3.9/lib/python/site-packages (2.1.1)
Install QGIS – I have version 3.30.1-‘s-Hertogenbosch, and it says it’s Python version 3.9.5, which is different to my actual installed version on my OS (3.9.6)
So, under the QGIS package in ‘Applications’ once it’s installed, right click and go Show Package Contents
Go to: Contents/Resources/python/site-packages/ <— that is where we will copy our files to
In another Finder window goto /Users//Library/Python/3.9/lib/python/site-packages/
Of course replace your username there…
I have the following folders in there:
pip-23.1.dist-info
pymysql
PyMySQL-1.0.3.dist-info
mysqlclient-2.1.1.dist-info
MySQLdb
pip
I copied all except the ‘pip’ folder just to be sure, although you may only need the MySQLdb and mysqlclient-2.1.1.dist-info folder. The ‘pip’ folder was already there so I didn’t replace it ‘cos it might mess something up.
Restart QGIS and reinstall the MySQL plugin, and it works!
How to Open MySQL Database From ArcGIS Pro - GIS Tutorial
December 21, 2023[…] QGIS users can make use of MySQL’s spatial extension to store spatial data, it may not be as straightforward for ArcGIS Pro users to directly utilize […]