Usage history of MySQL in Linux

Source: Internet
Author: User
Tags mysql client

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;

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.