I managed to import a layer from a MySQL database in QGIS with PyQGIS.
Now I'm looking to import a layer from QGIS into MySQL. I explored several ways :
- Using ogr2ogr on the command line, the loading was really very very slow.
- Using the MySQL Importer plugin: I looked at the script, it also uses
ogr2ogron the command line, the result was similar.
- Using PyQGIS (although I think it uses
ogr2ogrtoo). I encounter the following error:
Unable to load mysql data provider
My code is the following :
layer = iface.activeLayer() uri = "dbname='result' host=localhost port=3306 user='root' password='charlotte' key=id type=POINT table=\"result\".\"test\" (geom) sql=" crs = QgsCoordinateReferenceSystem() error = QgsVectorLayerExporter.exportLayer(layer, uri, "mysql", crs, False) if error != 0: iface.messageBar().pushMessage(u'Error', error, Qgis.Critical, 5)
I looked at the documentation which specifies that the method
QgsVectorLayerExporter.exportLayerwaits in 3rd parameter the providerKey. I tried several of them in vain.
I use QGIS 3.10.