I'd like to test the very simple C API connection with my MySQL server. And I'm using it on mac. So Here are the codes:
#include <stdio.h>
#include <mysql.h>
int main(void)
{
printf("MySQL client version: %s\n", mysql_get_client_info());
exit(0);
}
I use gcc to compile it
gcc -c `mysql_config --cflags` main.c
It succeeds. But when I tried to run it
./main.o
The error is like this
-bash: ./main.o: Permission denied
I can log in to the MySQL by anonymous and run select version():
shell>mysql
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.25 |
+-----------+
1 row in set (0.00 sec)
Thanks to Sean, there is a mistake in my compilation. It supposes to be
gcc -o main `mysql_config --cflags` main.c `mysql_config --libs`
After that when I run ./main I get another error:
dyld: Library not loaded: libmysqlclient.18.dylib
Thanks everyone!
I've solved this by adding the path of libmysqlclient.dylib to the DYLD_LIBRARY_PATH environment variable. Here is the command for someone may need it.
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib