Category: MySQL

How to connect to MySQL using TCL tdbc::mysql

Setting up a MySQL database connection using TCL on a Windows based machine should be easy.

When you enter package require tdbc::mysql, it should return the version of the tdbc package.

Unfortunately, the following error is displayed instead:

couldn’t load library “libmysql.dll.15”: this library or a dependent library could not be found in library path

Running TCL 8.6.9 Error Message executing command “package require tdbc::mysql”

The solution:

The message suggests the “libmysql.dll.15” or a dependent file could not be found in the library path. After searching my system, I discovered this and any related files didn’t exist on my machine.

Download MySQL Connector/C – Product Version 6.1.11 for Microsoft Windows. Download the ZIP Archive applicable to your machine (X86, 32-bit or X86, 64-bit).

Extract the zipped file into a local sub-directory. The “lib” directory contains the two files we need to copy TCL/bin directory: libmysql.dll and libmysql.lib.

To find out where TCL is installed, press the “Windows” key, search for the TCL command shell, or Tk graphical console, and right click the icon, click “more”, then click “open file location.”

This will bring you to the short cuts in the “Start Menu / Programs / sub-directory for your Tcl installation (Magicsplat Tcl 8.6.9 in my case.)

Right click on the Tcl command shell and click “Properties.” When the window opens, click “Open File Location”

This will open the “bin” directory for your Tcl installation. Copy libmysql.dll and libmysql.lib from the unzipped folder to the Tcl\bin directory.

Exit and restart the Tcl shell. The package require tdbc::mysql command now shows the tdbc version as expected. A subsequent command to create a connection was also successful.

package require tdbc::mysql

tdbc::mysql::connection create dbcnxn -user root -db sandbox

Now that we have a working connection, we can follow the documentation and carry on with the real work at hand.

If you’re wondering, yes, TCL is the language of choice for some applications. All in a day’s work.

You can also watch our video Making Connections – TCL and MySQL on Windows 10.

Until Next Time – STAY lean!

Related Articles and Resources

Advertisements