c mysql prepared,MySQL 5.1 英文手册 :: 21.9.4 C API Prepared Statements

21.9.4. C API Prepared Statements

The MySQL client/server protocol provides for the use of prepared

statements. This capability uses the MYSQL_STMT

statement handler data structure returned by the

mysql_stmt_init() initialization

function. Prepared execution is an efficient way to execute a

statement more than once. The statement is first parsed to prepare

it for execution. Then it is executed one or more times at a later

time, using the statement handle returned by the initialization

function.

Prepared execution is faster than direct execution for statements

executed more than once, primarily because the query is parsed

only once. In the case of direct execution, the query is parsed

every time it is executed. Prepared execution also can provide a

reduction of network traffic because for each execution of the

prepared statement, it is necessary only to send the data for the

parameters.

Prepared statements might not provide a performance increase in

some situations. For best results, test your application both with

prepared and nonprepared statements and choose whichever yields

best performance.

Another advantage of prepared statements is that it uses a binary

protocol that makes data transfer between client and server more

efficient.

The following SQL statements can be used as prepared statements:

CALL, CREATE

TABLE, DELETE,

DO,

INSERT,

REPLACE,

SELECT,

SET,

UPDATE, and most

SHOW statements.

As of MySQL 5.1.10, the following additional statements are

supported:

ANALYZE TABLE

OPTIMIZE TABLE

REPAIR TABLE

As of MySQL 5.1.12, the following additional statements are

supported:

CACHE INDEX

CHANGE MASTER

CHECKSUM {TABLE | TABLES}

{CREATE | RENAME | DROP} DATABASE

{CREATE | RENAME | DROP} USER

FLUSH {TABLE | TABLES | TABLES WITH READ LOCK | HOSTS | PRIVILEGES

| LOGS | STATUS | MASTER | SLAVE | DES_KEY_FILE | USER_RESOURCES}

GRANT

REVOKE

KILL

LOAD INDEX INTO CACHE

RESET {MASTER | SLAVE | QUERY CACHE}

SHOW BINLOG EVENTS

SHOW CREATE {PROCEDURE | FUNCTION | EVENT | TABLE | VIEW}

SHOW {AUTHORS | CONTRIBUTORS | WARNINGS | ERRORS}

SHOW {MASTER | BINARY} LOGS

SHOW {MASTER | SLAVE} STATUS

SLAVE {START | STOP}

INSTALL PLUGIN

UNINSTALL PLUGIN

Other statements are not yet supported in MySQL 5.1.

As of MySQL 5.1.25, metadata changes to tables or views referred

to by prepared statements are detected and cause automatic

repreparation of the statement when it is next executed. For more

information, see Section 12.6.4, “Automatic Prepared Statement Repreparation”.

MySQL Enterprise.

MySQL Enterprise subscribers will find more information about

using prepared statements in the Knowledge Base article,

How can I

create server-side prepared statements?. Access to the

MySQL Knowledge Base collection of articles is one of the

advantages of subscribing to MySQL Enterprise. For more

information, see http://www.mysql.com/products/enterprise/advisors.html.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值