mysql中的mysql_real_connect连接参数设置

摘要:
在前一篇文章中,讲述了如何进行mysql源程序代码的编译链接,但是没有讲述运行情况,在按照上一篇文章代码下进行编译运行后,发现无法链接数据库文件,显然是在mysql_real_connect()函数中出现了问题。
在前一篇文章中,讲述了如何进行mysql源程序代码的编译链接,但是没有讲述运行情况,在按照上一篇文章代码下进行编译运行后,发现无法链接数据库文件,显然是在mysql_real_connect()函数中出现了问题。在mysql的英文手册中找到关于mysql_real_connect()的如下描述:

//函数原型描述mysql中的mysql_real_connect连接参数设置第1张MYSQL*mysql_real_connect(MYSQL*mysql,constchar*host,constchar*user,
constchar*passwd,constchar*db,unsignedintport,constchar*unix_socket,
unsigned
longclient_flag)
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Description
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张mysql_real_connect()attemptstoestablishaconnectiontoaMySQLdatabaseengine
runningonhost.mysql_real_connect()mustcompletesuccessfullybeforeyoucan
executeanyotherAPIfunctionsthatrequireavalidMYSQLconnectionhandlestructure.
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Theparametersarespecified
asfollows:
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张ThefirstparametershouldbetheaddressofanexistingMYSQLstructure.Before
callingmysql_real_connect()youmustcallmysql_init()toinitializetheMYSQL
structure.Youcanchangealotofconnectoptionswiththemysql_options()call.
SeeSectionÂ
17.2.3.47,“mysql_options()”.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张ThevalueofhostmaybeeitherahostnameoranIPaddress.Ifhost
isNULLorthe
string
"localhost",aconnectiontothelocalhostisassumed.IftheOSsupportssockets
(Unix)ornamedpipes(Windows),theyareusedinsteadofTCP
/IPtoconnecttotheserver.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Theuserparametercontainstheuser
'sMySQLloginID.IfuserisNULLortheempty
string"",thecurrentuserisassumed.UnderUnix,thisisthecurrentloginname.Under
WindowsODBC,thecurrentusernamemustbespecifiedexplicitly.SeeSectionÂ18.1.9.2,
“ConfiguringaMyODBCDSNonWindows”.

mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Thepasswdparametercontainsthepassword
foruser.IfpasswdisNULL,onlyentries
intheusertablefortheuserthathaveablank(empty)passwordfieldarecheckedfora
match.Thisallowsthedatabaseadministratorto
setuptheMySQLprivilegesystemin
suchawaythatusers
getdifferentprivilegesdependingonwhethertheyhavespecified
apassword.
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Note:Donotattempttoencryptthepasswordbeforecallingmysql_real_connect();
passwordencryption
ishandledautomaticallybytheclientAPI.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张db
isthedatabasename.IfdbisnotNULL,theconnectionsetsthedefaultdatabase
to
thisvalue.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Ifport
isnot0,thevalueisusedastheportnumberfortheTCP/IPconnection.Note
thatthehostparameterdeterminesthetypeoftheconnection.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Ifunix_socket
isnotNULL,thestringspecifiesthesocketornamedpipethatshould
beused.Notethatthehostparameterdeterminesthetypeoftheconnection.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张Thevalueofclient_flag
isusually0,butcanbesettoacombinationofthefollowing
flagstoenablecertainfeatures:

mysql中的mysql_real_connect连接参数设置第1张//上面描述了五个参数的主要取值,MYSQL *为mysql_init函数返回的指针,host为null或 // localhost时链接的是本地的计算机,当mysql默认安装在unix(或类unix)系统中,root账户是没// 有密码的,因此用户名使用root,密码为null,当db为空的时候,函数链接到默认数据库,在进行 // mysql安装时会存在默认的test数据库,因此此处可以使用test数据库名称,port端口为0,使用 // unix连接方式,unix_socket为null时,表明不使用socket或管道机制,最后一个参数经常设置为0
mysql中的mysql_real_connect连接参数设置第1张FlagNameFlagDescription
mysql中的mysql_real_connect连接参数设置第1张CLIENT_COMPRESSUsecompressionprotocol.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_FOUND_ROWSReturnthenumberoffound(matched)rows,notthenumberof
changedrows.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_IGNORE_SPACEAllowspacesafterfunctionnames.Makesallfunctionsnames
reservedwords.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_INTERACTIVEAllowinteractive_timeoutseconds(insteadofwait_timeout
seconds)ofinactivitybeforeclosingtheconnection.Theclient
'ssessionwait_timeout
variableissettothevalueofthesessioninteractive_timeoutvariable.

mysql中的mysql_real_connect连接参数设置第1张
CLIENT_LOCAL_FILESEnableLOADDATALOCALhandling.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_MULTI_STATEMENTSTelltheserverthattheclientmaysendmultiple
statements
inasinglestring(separatedby‘;’).Ifthisflagisnotset,
multiple
-statementexecutionisdisabled.AddedinMySQL4.1.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_MULTI_RESULTSTelltheserverthattheclientcanhandlemultipleresult
setsfrommultiple
-statementexecutionsorstoredprocedures.Thisisautomatically
set
ifCLIENT_MULTI_STATEMENTSisset.AddedinMySQL4.1.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_NO_SCHEMADon
'tallowthedb_name.tbl_name.col_namesyntax.Thisisfor
ODBC.Itcausestheparsertogenerateanerrorifyouusethatsyntax,whichisuseful
fortrappingbugsinsomeODBCprograms.

mysql中的mysql_real_connect连接参数设置第1张
CLIENT_ODBCTheclientisanODBCclient.Thischangesmysqldtobemore
ODBC
-friendly.
mysql中的mysql_real_connect连接参数设置第1张CLIENT_SSLUseSSL(encryptedprotocol).Thisoptionshouldnotbe
setby
applicationprograms;it
issetinternallyintheclientlibrary.Instead,use
mysql_ssl_set()beforecallingmysql_real_connect().
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Forsomeparameters,it
ispossibletohavethevaluetakenfromanoptionfilerather
thanfroman
explicitvalueinthemysql_real_connect()call.Todothis,call
mysql_options()withtheMYSQL_READ_DEFAULT_FILEorMYSQL_READ_DEFAULT_GROUPoption
beforecallingmysql_real_connect().Then,
inthemysql_real_connect()call,specify
the“no
-value”valueforeachparametertobereadfromanoptionfile:
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Forhost,specifyavalueofNULLortheempty
string("").
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Foruser,specifyavalueofNULLortheempty
string.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Forpasswd,specifyavalueofNULL.(Forthepassword,avalueoftheempty
stringin
themysql_real_connect()callcannotbeoverriddeninanoptionfile,becausetheempty
stringindicatesexplicitlythattheMySQLaccountmusthaveanemptypassword.)
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Fordb,specifyavalueofNULLortheempty
string.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Forport,specifyavalueof
0.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Forunix_socket,specifyavalueofNULL.
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Ifnovalue
isfoundinanoptionfileforaparameter,itsdefaultvalueisusedas
indicated
inthedescriptionsgivenearlierinthissection.
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张ReturnValues
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张AMYSQL
*connectionhandleiftheconnectionwassuccessful,NULLiftheconnection
wasunsuccessful.Forasuccessfulconnection,the
returnvalueisthesameasthevalue
ofthefirstparameter.
// 返回值:当连接成功时,返回MYSQL连接句柄,失败,返回NULL。当成功时,返回值与第一个参数值是// 相同的。
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Errors
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_CONN_HOST_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtoconnecttotheMySQLserver.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_CONNECTION_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtoconnecttothelocalMySQLserver.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_IPSOCK_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtocreateanIPsocket.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_OUT_OF_MEMORY
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Outofmemory.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_SOCKET_CREATE_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtocreateaUnixsocket.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_UNKNOWN_HOST
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtofindtheIPaddress
forthehostname.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_VERSION_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Aprotocolmismatchresultedfromattemptingtoconnecttoaserverwithaclient
librarythatusesadifferentprotocolversion.Thiscanhappen
ifyouuseaveryold
clientlibrarytoconnecttoa
newserverthatwasn'tstartedwiththe--old-protocol
option.

mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_NAMEDPIPEOPEN_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张FailedtocreateanamedpipeonWindows.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_NAMEDPIPEWAIT_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Failedtowait
foranamedpipeonWindows.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_NAMEDPIPESETSTATE_ERROR
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Failedto
getapipehandleronWindows.
mysql中的mysql_real_connect连接参数设置第1张
*
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张CR_SERVER_LOST
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张Ifconnect_timeout
>0andittooklongerthanconnect_timeoutsecondstoconnectto
theserveror
iftheserverdiedwhileexecutingtheinit-command.
mysql中的mysql_real_connect连接参数设置第1张
mysql中的mysql_real_connect连接参数设置第1张
因此mysql_real_connect()函数调用为:
mysql_real_connect(mysql,"localhost","root",NULL,"test",0,NULL,0);
判断是否出错,出错调用mysql_error()函数显示出错信息,或使用mysql_errno()函数获取出错代号。

免责声明:文章转载自《mysql中的mysql_real_connect连接参数设置》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇【RabbitMQ】 RabbitMQ安装stegsolve使用方法下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

linux下导入导出MySQL数据库

一、导出:用mysqldump命令行命令格式mysqldump -u 用户名 -p 数据库名 > 数据库名.sql范例:mysqldump -u root -p abc > abc.sql(导出数据库abc到abc.sql文档)提示输入密码时,输入该数据库用户名的密码。 *************************************...

zabbix监控之概念和安装

一、为什么要要监控 (1)在需要的时刻,提前提醒我们服务器出问题了; (2)当出问题之后,可以找到问题的根源; (3)检查网站/服务器的可用性 1、监控范畴 硬件监控、系统监控、服务监控、性能监控、日志监控、安全监控、网络监控 2、监控方式 (1)远程管理服务器:需要有远程管理卡,比如:Dell idRA,CHP ILO,IBM IMM (2)监控硬件:查...

两种常见的mysql集群架构

常见的mysql集群架构 根据业务发展阶段和业务代码部署情况不同,对于扩展单数据库可以使用以下几种部署架构模型 单地域高可用架构 单地域高可用架构的构成 dbproxy数据库代理: 主要处理:读写分离,主从切换等。 主库(高可用):处理业务写流量。 从库(多实例,可选高可用):处理业务读流量。 单地域高可用的架构可以处理 业务流量在单地域的的业务结...

mysql-5.6.27源码安装及错误解决办法

环境:centos6.5.x86_64 wgethttp://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.27.tar.gz yum install -y cmake 当然也可以自己下载源码包安装,为方便就Yum安装了 useradd -s /sbin/nologin mysql tar zxvf mysql-...

详述一次大量删除导致MySQL慢查的分析

墨墨导读:监控上收到了大量慢查的告警,业务也反馈查询很慢,本文记录整个慢查的原因,以及解决方案。 一、背景监控上收到了大量慢查的告警,业务也反馈查询很慢,随即打开电脑确认慢查的原因。 二、现象描述通过平台的慢查分析之后,我们发现慢查有以下特征: 慢查的表名都是 sbtest1,没有其他的表; 大部分的慢查都是查表最新的数据,例如 select * f...

国产系统安装docker-ce、配置mysql

银河麒麟安装docker 一、安装 添加用户组和用户,非root启动docker groupadd docker useradd -m -g docker docker -s /sbin/nologin 添加权限 sudo tee /etc/sudoers.d/docker >/dev/null <<EOF docker ALL=(AL...