Setting Up Connector/C and SkySQL C Connector for MySQL and MariaDB

I’m writing a post on how to create your first C/C++ program for MySQL (using Windows, and from the command line). A prerequisite for that is to have a C Connector, such as MySQL Connector/C or SkySQL C Connector, so the program can communicate with mysqld.

I didn’t want that post to be too scattered, so I decided to split it into two, more focused posts. That said, this first post will focus on the Connector, and the next post will actually cover the program itself.

Installing and using Connector/C with MySQL is quite simple, so I wanted to show how easy it is. I also wanted to show examples with both SkySQL C Connector with MariaDB (which also works with MySQL) and Connector/C with MySQL, since both are widely used. I also wanted to show some common errors one might encounter and their resolutions, so hopefully this will help anyone who might have issues along the way.

SkySQL C Connector & MariaDB:

1. Download SkySQL C Connector and extract to:

C:\Program Files\MySQL\mariadb_client-1.0.0

2. Test the Connector per the Docs:

cd C:\Program Files\MariaDB 5.5\bin
mysql_client_test -uroot -p -P3314

or:

"C:\Program Files\MariaDB 5.5\bin\mysql_client_test" -uroot -p -P3314

Connector/C & MySQL:

1. Download Connector/C extract to:

C:\Program Files\MySQL\MySQL Connector C 6.1

2. Test the Connector per the Docs:

cd C:\Program Files\MySQL\MySQL Server 5.5\bin
mysql_client_test -uroot -p -P3308

or:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql_client_test" -uroot -p -P3308

Outputs:

SkySQL C Connector & MariaDB:

#####################################
client_connect
#####################################

 Establishing a connection to '' ...OK
Connected to MySQL server version: 5.5.31-MariaDB (50531)

 Creating a test database 'client_test_db' ...OK

#####################################
1 of (1/1): test_view_sp_list_fields
#####################################
...
tons of test output
...

Connector/C & MySQL:

#####################################
client_connect
#####################################

 Establishing a connection to '' ...OK
Connected to MySQL server version: 5.5.32-log (50532)

 Creating a test database 'client_test_db' ...OK

#####################################
1 of (1/1): test_view_sp_list_fields
#####################################
...
tons of test output
...

Errors & Fixes:

This was very straight-forward overall, and I only ran into 2 quite basic issues, but want to share them here for completeness and in case anyone else runs into the same:

1. When I first invoked mysql_client_test, I received the following error:

mysql_client_test: unknown variable 'default-character-set=utf8'

This just means I had ‘default-character-set=utf8′ set under the [client] section in my config file, and apparently this option cannot be read by mysql_client_test. The simple fix is to add the “loose-” prefix to this option in the config file:

[client]
loose-default-character-set=utf8

Now, you can run the file without encountering this error. Instead, you’ll just see a “warning” now about “unknown variable ‘loose-default-character-set=utf8′”. :)

Note there is *no* need to restart mysqld after making this change, since the change only applies ‘clients’ and not the server (i.e., mysqld).

2. The only other error I could stumble into is:

Establishing a connection to '' ... [MySQL] connection failed

And that was just because I invoked mysql_client_test without –user and –password options.

Hope this helps. :)

 

Tags: , , , , , , , , , , , , , , , , ,

Comments are closed.


Period Panties by Period Panteez Menstrual Underwear Menstruation PMS Panty