3

On a mac (Mountain Lion), after a major upgrade to GDAL (1.10) and related frameworks from KyngChaos page, QGIS 2.0 doesn't show any MySQL connector:

Add Vector > Database > ...

The driver doesn't appear neither in the terminal running the "ogr2ogr --formats" command. I read (link), at the very end of the post, that this feature has been removed from QGIS 2.0. Anyway, it appears to me that it depends on GDAL/OGR: it seems that the framework has been build without MySQL support.

2
  • 1
    on my, does not work. when I try to open the database qgis crash Process: QGIS [53751] Path: /Applications/QGIS.app/Contents/MacOS/QGIS Identifier: org.qgis.qgis Version: 2.2.0 (2.2.0 []) Code Type: X86-64 (Native) Parent Process: launchd [276] Responsible: QGIS [53751] User ID: 501 Date/Time: 2014-03-17 10:33:37.731 +0000 OS Version: Mac OS X 10.9.2 (13C64) Report Version: 11 Anonymous UUID: 210BA7B3-460E-3614-9E8A-1E836F758714 Sleep/Wake UUID: BCF76B4E-5922-4758-B01A-96F78B8E247E Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Codes: Commented Mar 17, 2014 at 10:36
  • I think previous comment was intended as a response to the posted answer, not the question itself. I followed the steps in the answer (except that I did not edit any files as in step 4 and I used gdal-1.11.3) and ran into same exception - segmentation fault EXC_BAD_ACCESS (SIGSEGV)
    – morpheus
    Commented Apr 27, 2016 at 18:59

1 Answer 1

4

It doesn't look like it is included in the most recent GDAL-Complete framework. Please file a request with kyngchaos.com.

In the meantime, if you don't mind trying it yourself, you can attempt to build a shared plugin for GDAL 1.10, install it, and see if it works with your data source:

  1. Ensure you have XCode and/or its command line tools installed.

  2. Download and install latest MySQL Community Server (installs to /usr/local/mysql).

  3. Download the GDAL source and un-archive to folder, e.g. gdal-1.10.1, and enter it.

    $ cd /path/to/gdal-1.10.1
    
  4. Edit a single source file and comment-out unsupported symbols in MySQL 5.6+ client

    ogr/ogrsf_frmts/mysql/ogrmysqldatasource.cpp @ line 130

    /* -------------------------------------------------------------------- */
    /*      Use options process to get .my.cnf file contents.               */
    /* -------------------------------------------------------------------- */
        int nPort = 0, i;
        char **papszTableNames=NULL;
        std::string oHost, oPassword, oUser, oDB;
    //     char *apszArgv[2] = { (char*) "org", NULL };
    //     char **papszArgv = apszArgv;
    //     int  nArgc = 1;
    //     const char *client_groups[] = {"client", "ogr", NULL };
    
        my_init(); // I hope there is no problem with calling this multiple times!
    //     load_defaults( "my", client_groups, &nArgc, &papszArgv );
    // 
    //     for( i = 0; i < nArgc; i++ )
    //     {
    //         if( EQUALN(papszArgv[i],"--user=",7) )
    //             oUser = papszArgv[i] + 7;
    //         else if( EQUALN(papszArgv[i],"--host=",7) )
    //             oHost = papszArgv[i] + 7;
    //         else if( EQUALN(papszArgv[i],"--password=",11) )
    //             oPassword = papszArgv[i] + 11;
    //         else if( EQUALN(papszArgv[i],"--port=",7) )
    //             nPort = atoi(papszArgv[i] + 7);
    //     }
    // 
    //     // cleanup
    //     free_defaults( papszArgv );
    
  5. Build shared plugin, in Terminal:

    # make directory for build output
    $ mkdir ogr_plugins
    
    # compile shared plugin, statically linking in libmysqlclient (multi-line, single command)
    $ g++ -Wall -g ogr/ogrsf_frmts/mysql/*.c* \
    -shared -o ogr_plugins/ogr_MySQL.dylib /usr/local/mysql/lib/libmysqlclient.a \
    -Iport -Igcore -Iogr -Iogr/ogrsf_frmts -Iogr/ogrsf_frmts/mysql \
    -I/Library/Frameworks/GDAL.framework/Headers -I/usr/local/mysql/include \
    -framework GDAL -lz -install_name ogr_MySQL.dylib
    
    */ #just closing comment for SE syntax highlighting 
    
    # copy plugin to known GDAL_DRIVER_PATH (sudo needed)
    $ cd ogr_plugins
    $ sudo cp -f ogr_MySQL.dylib /Library/Application\ Support/GDAL/1.10/PlugIns/
    
  6. Verify plugin:

    $ cd /path/to/gdal-1.10.1
    $ otool -L ogr_plugins/ogr_MySQL.dylib
    ogr_plugins/ogr_MySQL.dylib:
            ogr_MySQL.dylib (...)
            /Library/Frameworks/GDAL.framework/Versions/1.10/GDAL (...)
            /usr/lib/libz.1.dylib (...)
            /usr/lib/libstdc++.6.dylib (...)
            /usr/lib/libSystem.B.dylib (...)
    
    $ ogrinfo --formats | grep 'MySQL'
    -> "MySQL" (read/write)
    
  7. Launch QGIS and verify plugin loading in PyQGIS console:

    from osgeo import ogr
    sorted([ogr.GetDriver(drv).name for drv in range(0,ogr.GetDriverCount())])
    
  8. You should be able to connect to a MySQL data source via Add Vector > Database > ... now.

Please note, I don't have any geospatial MySQL data sources, so was unable to test the plugin I built.

2
  • I can test the plugin (and the method as well) with a MySQL geospatial point table. It works!
    – Pankus
    Commented Oct 15, 2013 at 10:40
  • dakcarto, your answer works through QGIS 2.14.3 (KyngChaos) but breaks at 2.18.0 when GDAL is migrated to 2.1 from 1.10.1. I've tried to use your methodology, but I failed. Do you mind taking another look?
    – gNat
    Commented Nov 10, 2016 at 20:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.