mysql中的mysql_real_connect连接参数设置

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

//函数原型描述 MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user,
const char *passwd, const char *db, unsigned int port, const char *unix_socket,
unsigned 
long client_flag)

Description

mysql_real_connect() attempts to establish a connection to a MySQL database engine
running on host. mysql_real_connect() must complete successfully before you can
execute any other API functions that require a valid MYSQL connection handle structure.

The parameters are specified 
as follows:

    
*

      The first parameter should be the address of an existing MYSQL structure. Before
 calling mysql_real_connect() you must call mysql_init() to initialize the MYSQL
structure. You can change a lot of connect options with the mysql_options() call.
See Section 
17.2.3.47, Â“mysql_options()”.
    
*

      The value of host may be either a hostname or an IP address. If host 
is NULL or the
string
 "localhost", a connection to the local host is assumed. If the OS supports sockets
(Unix) or named pipes (Windows), they are used instead of TCP
/IP to connect to the server.
    
*

      The user parameter contains the user
's MySQL login ID. If user is NULL or the empty
string "", the current user is assumed. Under Unix, this is the current login name. Under
 Windows ODBC, the current username must be specified explicitly. See Section 18.1.9.2,
 Â“Configuring a MyODBC DSN on Windows”.

    *

      The passwd parameter contains the password 
for user. If passwd is NULL, only entries
 
in the user table for the user that have a blank (empty) password field are checked for a
match. This allows the database administrator to 
set up the MySQL privilege system in
such a way that users 
get different privileges depending on whether they have specified
a password.

      Note: Do not attempt to encrypt the password before calling mysql_real_connect();
 password encryption 
is handled automatically by the client API.
    
*

      db 
is the database name. If db is not NULL, the connection sets the default database
to 
this value.
    
*

      If port 
is not 0, the value is used as the port number for the TCP/IP connection. Note
that the host parameter determines the type of the connection.
    
*

      If unix_socket 
is not NULL, the string specifies the socket or named pipe that should
 be used. Note that the host parameter determines the type of the connection.
    
*

      The value of client_flag 
is usually 0, but can be set to a combination of the following
flags to enable certain features:

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

      Flag Name    Flag Description
      CLIENT_COMPRESS    Use compression protocol.
      CLIENT_FOUND_ROWS    Return the number of found (matched) rows, not the number of
 changed rows.
      CLIENT_IGNORE_SPACE    Allow spaces after function names. Makes all functions names
reserved words.
      CLIENT_INTERACTIVE    Allow interactive_timeout seconds (instead of wait_timeout
seconds) of inactivity before closing the connection. The client
's session wait_timeout
variable is set to the value of the session interactive_timeout variable.

      CLIENT_LOCAL_FILES    Enable LOAD DATA LOCAL handling.
      CLIENT_MULTI_STATEMENTS    Tell the server that the client may send multiple
statements 
in a single string (separated by Â‘;Â’). If this flag is not set,
multiple
-statement execution is disabled. Added in MySQL 4.1.
      CLIENT_MULTI_RESULTS    Tell the server that the client can handle multiple result
sets from multiple
-statement executions or stored procedures. This is automatically
set
 if CLIENT_MULTI_STATEMENTS is set. Added in MySQL 4.1.
      CLIENT_NO_SCHEMA    Don
't allow the db_name.tbl_name.col_name syntax. This is for
ODBC. It causes the parser to generate an error if you use that syntax, which is useful
 for trapping bugs in some ODBC programs.

      CLIENT_ODBC    The client is an ODBC client. This changes mysqld to be more
 ODBC
-friendly.
      CLIENT_SSL    Use SSL (encrypted protocol). This option should not be 
set by
application programs; it 
is set internally in the client library. Instead, use
mysql_ssl_set() before calling mysql_real_connect().

For some parameters, it 
is possible to have the value taken from an option file rather
than from an 
explicit value in the mysql_real_connect() call. To do this, call
mysql_options() with the MYSQL_READ_DEFAULT_FILE or MYSQL_READ_DEFAULT_GROUP option
before calling mysql_real_connect(). Then, 
in the mysql_real_connect() call, specify
the Â“no
-value” value for each parameter to be read from an option file:

    
*

      For host, specify a value of NULL or the empty 
string ("").
    
*

      For user, specify a value of NULL or the empty 
string.
    
*

      For passwd, specify a value of NULL. (For the password, a value of the empty 
string in
 the mysql_real_connect() call cannot be overridden in an option file, because the empty
string indicates explicitly that the MySQL account must have an empty password.)
    
*

      For db, specify a value of NULL or the empty 
string.
    
*

      For port, specify a value of 
0.
    
*

      For unix_socket, specify a value of NULL. 

If no value 
is found in an option file for a parameter, its default value is used as
indicated 
in the descriptions given earlier in this section.

Return Values

A MYSQL
* connection handle if the connection was successful, NULL if the connection
was unsuccessful. For a successful connection, the 
return value is the same as the value
of the first parameter.
// 返回值:当连接成功时,返回MYSQL连接句柄,失败,返回NULL。当成功时,返回值与第一个参数值是// 相同的。

Errors

    
*

      CR_CONN_HOST_ERROR

      Failed to connect to the MySQL server.
    
*

      CR_CONNECTION_ERROR

      Failed to connect to the local MySQL server.
    
*

      CR_IPSOCK_ERROR

      Failed to create an IP socket.
    
*

      CR_OUT_OF_MEMORY

      Out of memory.
    
*

      CR_SOCKET_CREATE_ERROR

      Failed to create a Unix socket.
    
*

      CR_UNKNOWN_HOST

      Failed to find the IP address 
for the hostname.
    
*

      CR_VERSION_ERROR

      A protocol mismatch resulted from attempting to connect to a server with a client
library that uses a different protocol version. This can happen 
if you use a very old
client library to connect to a 
new server that wasn't started with the --old-protocol
option.

    *

      CR_NAMEDPIPEOPEN_ERROR

      Failed to create a named pipe on Windows.
    
*

      CR_NAMEDPIPEWAIT_ERROR

      Failed to wait 
for a named pipe on Windows.
    
*

      CR_NAMEDPIPESETSTATE_ERROR

      Failed to 
get a pipe handler on Windows.
    
*

      CR_SERVER_LOST

      If connect_timeout 
> 0 and it took longer than connect_timeout seconds to connect to
the server or 
if the server died while executing the init-command. 

 

    因此mysql_real_connect()函数调用为:
       mysql_real_connect(mysql,"localhost","root",NULL,"test",0,NULL,0);
判断是否出错,出错调用mysql_error()函数显示出错信息,或使用mysql_errno()函数获取出错代号。
实战演练 | ABAQUS显式动力学分析在金属切削仿真中的应用 本文详细介绍了如何利用ABAQUS显式动力学分析进行金属切削过程的二维仿真。通过从零开始的完整流程,包括几何建模、材料本构与失效定义、网格划分、接触设置、边界条件施加,到结果后处理与切削力提取,为工程师和研究人员提供了实用的仿真方法,以优化刀具设计和加工工艺。 阅读详情

相关推荐

DEAP数据集实战:用PyTorch搭建DNN/CNN脑电情绪识别模型(附完整代码)

本文详细介绍了如何使用PyTorch搭建DNN和CNN模型对DEAP数据集进行脑电情绪识别。从数据预处理到模型架构设计,再到训练优化和部署,提供了完整的实战指南和代码示例,帮助研究者快速掌握脑电信号识别技术。

k8l9m0n的博客 392

MySQL-mysql_real_connect()函数介绍

头文件 #include<mysql.h> 函数原型描述:   MYSQL *mysql_real_connect (MYSQL *mysql,   const char *host,   const char *user,   const char *passwd,   const char *db,   unsigned int port,   const char *unix_socket,   unsigned long client_flag) 上面描述了五个参数的主要取值,   MY

李木子的博客 8581

Verilog基本代码结构及常用语句always、begin...end解读

Verilog基本代码结构及常用语句always、begin...end解读 线性反馈以为寄存器(LFSR)

weixin_62380586的博客 1万+

mysql_real_connect()

函数原型:MYSQLmysqlrealconnect(MYSQLmysql,constcharhost,constcharuser,constcharpasswd,constchardb,unsignedintport,constcharunixsocket,unsignedintclientflag) 说明:mysql_real_connect()试图建...

weixin_33711647的博客 2308

OpenWrt国内镜像源一键切换脚本:清华/阿里/中科大源全搞定

本文介绍了OpenWrt国内镜像源一键切换脚本,支持清华、阿里和中科大三大源,自动识别设备架构和系统版本,显著提升软件包安装速度和成功率。脚本包含架构自动识别、版本适配、多源选择和配置备份等功能,适用于x86_64、ramips/mt7621等常见架构,帮助用户解决海外源访问缓慢的问题。

g5h6i的博客 1176

Temporal Noise Reduction(TNR)时序去噪技术解析:原理、平台实践与工程调优路径

随着高画质夜景拍照和高清视频拍摄需求的持续增长,图像传感器在低照度环境下输出信号的噪声问题日益突出。相比空间域降噪(SNR),时序去噪(Temporal Noise Reduction, TNR)利用帧间信息进行融合处理,具备更高的信噪比提升效率及更强的边缘保护能力,已成为移动影像ISP链路中的核心环节。本文系统剖析TNR的算法原理、平台实现机制与工程调试路径,并基于实际开发案例分析其在不同场景下的效果差异及调优方法,为工程师提供从理论到实操的完整路径参考。

努力分享一些人工智能、计算机视觉、影像等相关的知识干货! 3205

C++多线程数据库连接池MySQL

C++ 调用 MYSQL API 连接池 多线程

从事Android BSP 工程师,日常开发些APK,分享调试记录等信息 2287

【Bug已解决】[Bug]: ValueError: No user query found in messages QWEN 3.5 27B VLLM 0.16.0 NIGHTLY 解决方案

用 vLLM 0.16.0 nightly 给发聊天请求时,服务端在处理消息时抛ValueError,请求失败。

博客 409

mysql_real_connect传参_mysql中的mysql_real_connect连接参数设置

//函数原型描述 MYSQL*mysql_real_connect(MYSQL*mysql,constchar*host,constchar*user,constchar*passwd,constchar*db,unsignedintport,constchar*unix_socket,unsignedlongclient_flag)Descriptionmysql_real_connect()...

weixin_35985795的博客 431

C#上位机实战:Modbus RTU串口通信(CRC校验+超时重发完整实现)

在工业自动化上位机开发中,Modbus RTU是串口通信的事实标准协议,SerialPort是 .NET 平台操作串口的原生类,无需依赖第三方库即可实现基础通信。实际项目中,工控现场存在电磁干扰、串口丢包、设备响应延迟等问题,CRC 数据校验用于保证报文完整性,超时重发机制用于提升通信稳定性。本文从零封装一套可直接落地的 Modbus RTU 通信组件,包含完整的校验算法、超时控制、重发逻辑,并配套 WinForm 演示界面。本文基于 C# 原生SerialPort类,实现了一套生产可用。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 389

08-StarRocks性能调优FAQ

StarRocks性能调优摘要 本文提供了StarRocks数据库性能调优的常见问题解答,涵盖查询优化、索引设计、分区策略和系统配置等关键方面。主要内容包括:查询优化技巧(使用EXPLAIN分析、避免全表扫描、优化JOIN和聚合查询);索引选择与维护建议(高频查询列索引、复合索引);分区策略设计(时间分区、范围分区)及其管理方法;以及系统内存配置优化(JVM参数调整、查询内存限制设置)。这些优化措施可显著提升StarRocks的查询性能和系统效率。

欢迎来到我的博客,一起探索代码里的世界! 541

mysql_real_connect 参数注意

mysql_real_connect的声明: MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned...

weixin_34291004的博客 831

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

mysql mysql_real_connect_MySQL数据库中MySQL_real_connect的基本设置

此文章主要向大家讲述的是MySQL数据库中的MySQL_real_connect 连接参数的基本设置,我们在前一篇文章讲述关于进行MySQL(和PHP搭配之***组合)源程序代码的编译链接,但是没有讲述运行情况,在按照上一篇文章代码下进行编译运行后。发现无法链接数据库文件,显然是在MySQL(和PHP搭配之***组合)_real_connect()函数中出现了问题。在MySQL(和PHP搭配之**...

weixin_35689019的博客 1350

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

mysql mysql_real_connect_MySQL基础知识———mysql_real_connect() | 学步园

mysql_real_connect()MYSQL *mysql_real_connect(MYSQL*mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_flag...

weixin_30404433的博客 1224

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

mysql中real代表什么意思_MySQL数据库中MySQL_real_connect的基本设置

此文章主要向大家讲述的是MySQL数据库中的MySQL_real_connect连接参数的基本设置,我们在前一篇文章讲述关于进行MySQL(和PHP搭配之最佳组合)源程序代码的编译链接,但是没有讲述运行情况,在按照上一篇文章代码下进行编译运行后。发现无法链接数据库文件,显然是在MySQL(和PHP搭配之最佳组合)_real_connect()函数中出现了问题。在MySQL(和PHP搭配之最佳组合)...

weixin_26875543的博客 1270

mysql 交互式连接和非交互式连接

交互式客户端定义为在mysql_real_connect()中使用CLIENT_INTERACTIVE选项的客户端 mysql_real_connect() 函数介绍 函数原型描述:MYSQL *mysql_real_connect(MYSQL *mysql,const char *host,const char *user,const char *passwd,con...

weixin_30580341的博客 376

mysql和vs_mysql和VS2010 C++链接过程中出现的问题

这篇博客园的文章中的代码已经被我改好,附到下面去了!1.在C++和mysql连接编译遇到的第一个问题:error LNK2019: 无法解析的外部符号 _mysql_real_connect@32,该符号在函数 _main 中被引用error LNK2019: 无法解析的外部符号 _mysql_query@8,该符号在函数 _main 中被引用error LNK2019: 无法解析的外部符号 _m...

weixin_34160181的博客 275

CC++链接数据库(MySQL)超级详细指南

在C/C++编程中,与数据库进行交互是一项常见的任务。其中,"host"是数据库服务器的地址,"user"是数据库用户名,"password"是数据库密码,"database"是要连接的数据库名称。在使用C/C++链接MySQL数据库之前,需要确保你的开发环境中已经安装了MySQL数据库以及相应的开发库。你需要在你的C/C++项目中配置这些路径,以便编译器和链接器能够找到MySQL的头文件和库文件。在你的C/C++项目中,你需要引入MySQL的头文件,并在编译时链接MySQL的库文件。

wang245598199的博客 385

mysql_real_connect传参_mysql_real_connect 参数注意

mysql_real_connect的声明:MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_f...

weixin_29234509的博客 198

mysql connect 参数_mysql_real_connect 参数注意

mysql_real_connect的声明:MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_f...

weixin_34669783的博客 756

mysql_real_connect 有效期_mysql_real_connect 参数注意

mysql_real_connect的声明:MYSQL *mysql_real_connect(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long client_f...

weixin_42153793的博客 176

mysql real connect_MySQL教程和mysql_real_connect()用法

MYSQL *mysql_real_connect(MYSQL *mysql, const char *host,const char *user, const char *passwd, const char *db, unsigned intport, const char *unix_socket, unsigned longclient_flag)描述mysql_real_connect(...

weixin_35198152的博客 1311
上一篇: Linux下进行MYSQL的C++编程起步手记
下一篇: Hash函数学习笔记
newrain021011
博客等级 码龄22年 17粉丝 47原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值