Tutorial
Http://zetcode.com/tutorials/mysqlcapitutorial/
Install mysql-connector-c-6.0.2.tar.gz
That is, the MySQL C Client
Yum groupinstall "development tools"
Cmake.
Make
Make install
LDD is used to view dependencies.
LD. So. conf is used to load the path at runtime.
Use ldconfig
The root account of MySQL. I usually use localhost or 127.0.0.1 during connection. The MySQL on the testing server of the company is also localhost. Therefore, I want to access the root account and the test is paused.
The solution is as follows:
1. Modify the table, log on to the MySQL database, switch to the MySQL database, and use the SQL statement to view "select host, user from user ;"
Mysql-u root-pvmwaremysql> use MySQL;
Mysql> Update user set host = '%' where user = 'root ';
Mysql> select host, user from user;
Mysql> flush privileges;
Note: The last sentence is very important to make the modification take effect. If there is no write, remote connection is still not allowed.
2. Authorize the user. You want the root user to use the password to connect to the MySQL server from any host.
Grant all privileges on *. * To 'root' @ '%' identified by 'root' with grant option;
Flush privileges;
If you want to allow the user root to connect to the MySQL server from a host with the IP address 192.168.1.104
Grant all privileges on *. * To 'myuser' @ '192. 168.1.104 'identified by 'zhoubt' with grant option;
Flush privileges;
Use mysql_config -- libs to generate dependent items
Use dynamic compilation, but use static libmysqlclient.
G ++./test_mysql.cpp-I/usr/local/MySQL/include/usr/local/MySQL/lib/libmysqlclient. A-lpthread
Use static Compilation
G ++-static./test_mysql.cpp-I/usr/local/MySQL/include/usr/local/MySQL/lib/libmysqlclient. A-lpthread
Use Dynamic compiling libmysql. So
G ++./test_mysql.cpp-I/usr/local/MySQL/include-L/usr/local/MySQL/lib-lmysql-lpthread
Source code:
# Include <cstdlib>
# Include <cstdio>
# Include <mysql. h>
Int main ()
{
Printf ("===\ N ");
Printf ("MYSQL client version: % s \ n", mysql_get_client_info ());
MySQL * conn;
Conn = mysql_init (null );
If (conn = NULL ){
Printf ("error % u: % s \ n", mysql_errno (conn), mysql_error (conn ));
Exit (1 );
}
If (mysql_real_connect (Conn, "192.168.1.108", "root ",
"Zhoubt", null, 3306, null, 0) = NULL ){
Printf ("error % u: % s \ n", mysql_errno (conn), mysql_error (conn ));
Exit (1 );
}
If (mysql_query (Conn, "create database testdb ")){
Printf ("error % u: % s \ n", mysql_errno (conn), mysql_error (conn ));
Exit (1 );
}
Mysql_close (conn );
Return 0;
}