Therefore, the procedure can be used for various SBCs with different architectures. An advantage for this approach is that we can use the same C++ code for both MsSQL server and MySQL server just by changing the DSN. At first, following tools need to be installed in the machine.
sudo apt install mysql-client libmysqlclient-dev sudo apt install unixodbc unixodbc-dev sudo apt install libgtk-3-dev cmake sudo apt install libssl-dev
Getting the SourceConnector/ODBC can be obtained at the following link. As we want to build it from the source, choose 'Source Code' in the 'Select Operating System' drop down box and choose 'Generic Linux (Architecture Independent)' in the 'Select OS Version' drop down box.
Extract the file and make a directory to build.
$ tar zxvf ~/Downloads/mysql-connector-odbc-8.0.13-src.tar.gz $ cd mysql-connector-odbc-8.0.13-src/ $ mkdir build $ cd build
Building and InstallingWe can build and install the the downloaded source using cmake as follows. [Ora18a]။
$ cmake .. -G "Unix Makefiles" -DWITH_UNIXODBC=1 $ make $ sudo make installIn case, there is an error in finding MySQL headers and libraries, you can define the paths like
$ export MYSQL_INCLUDE_DIR=/usr/local/mysql/include $ export MYSQL_LIB_DIR=/usr/local/mysql/lib $ export MYSQL_DIR=/usr/local/mysqlThereafter, the following libraries can be found in /usr/local/lib.
$ find / -name 'lib*odbc*.so'
DSNTo register ODBC driver [Coo18a, Ora18b], /etc/odbcinst.ini can be edited as follow.
$ sudo nano /etc/odbcinst.iniWhen it is opened, fill up the following, save the changes, and exit by pressing ctrl+o and ctrl+x.
[myodbc8a] Description = Connector/ODBC 8.0 ANSI Driver DSN Driver = /usr/local/lib/libmyodbc8a.so Setup = /usr/local/lib/libmyodbc8S.so [myodbc8w] Description = Connector/ODBC 8.0 UNICODE Driver DSN Driver = /usr/local/lib/libmyodbc8w.so Setup = /usr/local/lib/libmyodbc8S.soThen, ODBC Data Source Name (DSN) can be defined in /etc/odbc.ini. Enter
$ sudo nano /etc/odbc.iniand fill the DSNs as shown below.
[ODBC Data Sources] myodbc8w = MyODBC 8.0 UNICODE Driver DSN myodbc8a = MyODBC 8.0 ANSI Driver DSN [myodbc8w] Driver = /usr/local/lib/libmyodbc8w.so Description = Connector/ODBC 8.0 UNICODE Driver DSN SERVER = localhost PORT = 3306 USER = Password = Database = mytest OPTION = 3 SOCKET = [myodbc8a] Driver = /usr/local/lib/libmyodbc8a.so Description = Connector/ODBC 8.0 ANSI Driver DSN SERVER = localhost PORT = 3306 USER = Password = Database = mytest OPTION = 3 SOCKET =USER , Password, and SOCKET can be left blank. In case of socket error, the path for mysqld.sock can be define like
SOCKET = /var/run/mysqld/mysqld.sock
To test the database, isql command line tool can be used to connect to 'myodbc8a' as follow.
$ isql -v myodbc8aIf the library cannot be opened and file not found error is encountered, client library 'libmysqlclient.so.21' can be copied as follow.
$ sudo cp /usr/local/mysql/lib/libmysqlclient.so.21 /usr/local/lib/Thereafter, ODBC client applications can use these DSNs as discussed in the following post.
Using MS SQL Server from C++ with wxWidgets
[Ora18a] Oracle. Building Connector/ODBC from a Source Distribution on Unix. 2018.
[Ora18b] Oracle. Configuring a Connector/ODBC DSN on Unix. 2018.
[Coo18a] Cool Emerald. Using Microsoft SQL Server from Linux Machines with ODBC & FreeTDS. 2018.