freebsd 安装 mysql
1. freebsd 这个系统说实话 真的没有ubuntu 方便 ,要安装个软件, apt-get install 下就可以了,而在freebsd 下面只能在ports 下去装,但通常情况下总是没资源,坑啊
所以只能自己 下包,自己装了
1. 首先下 mysql-5.1.70.tar.gz
#include <iostream> #include <string.h> #include "mysql.h" //安装的mysql的头文件所在的位置 using namespace std; string host = "192.168.67.130"; string user = "root"; string pwd = "123456"; string dbname = "test"; string sql = "select * from user"; unsigned int port = 3306; // int status; int main() { MYSQL *mysql; mysql = mysql_init(0); MYSQL_RES *result; MYSQL_ROW row; if (mysql_real_connect(mysql, host.c_str(), user.c_str(), pwd.c_str(), dbname.c_str(), port, NULL, CLIENT_FOUND_ROWS) == NULL){ cout << "connect failure!" << endl; return EXIT_FAILURE; } else{ cout << "connect success!" << endl; } mysql_set_character_set(mysql, "gbk"); status = mysql_query(mysql, sql.c_str()); if (status != 0){ cout << "query failure!" << endl; } cout << "the status is :" << status << endl; result = mysql_store_result(mysql); while (row = mysql_fetch_row(result)){ cout << row[1] << "|" << row[2] << endl; } mysql_free_result(result); mysql_close(mysql); }
g++ -o testmysql testmysql.cpp -lmysqlclient -I /usr/local/mysql/include/mysql -L /usr/local/mysql/lib/mysql/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。