首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >/*!*/;在mysql中的用途是什么?

/*!*/;在mysql中的用途是什么?
EN

Database Administration用户
提问于 2011-12-21 19:50:35
回答 1查看 606关注 0票数 3

标题很大程度上概括了我的问题。

他们似乎出现在每一次陈述之后。

有时在一条新的线路后面。在其他时候,在;结束之前。

这有什么意义呢?

EN

回答 1

Database Administration用户

回答已采纳

发布于 2011-12-21 20:21:24

它们显然是二进制日志中的标记,用于根据发出的命令的上下文处理内部语句。

当您对二进制日志执行mysqlbinlog时,您会看到它充当分隔符。MySQL也有机会处理特定版本的MySQL所固有的某些指令,从而引出二进制日志。

示例:

我运行了以下命令:

代码语言:javascript
复制
reset master;
use test
show binary logs;
create table rolandotable (a int);
show binary logs;
insert into rolandotable values (1);
flush logs;
show binary logs;

我拿到了这个:

代码语言:javascript
复制
mysql> reset master;
Query OK, 0 rows affected (0.21 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       107 |
+------------------+-----------+
1 row in set (0.01 sec)

mysql> use test
Database changed
mysql> create table rolandotable (a int);
Query OK, 0 rows affected (0.22 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       203 |
+------------------+-----------+
1 row in set (0.00 sec)

mysql> insert into rolandotable values (1);
Query OK, 1 row affected (0.05 sec)

mysql> flush logs;
Query OK, 0 rows affected (0.18 sec)

mysql> show binary logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       439 |
| mysql-bin.000002 |       107 |
+------------------+-----------+
2 rows in set (0.00 sec)

下面是mysql-bin.0001的mysqlbinlog转储。

代码语言:javascript
复制
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
# at 4
#111221 14:56:13 server id 1  end_log_pos 107   Start: binlog v 4, server v 5.5.12-log created 111221 14:56:13 at startup
ROLLBACK/*!*/;
BINLOG '
3TnyTg8BAAAAZwAAAGsAAAAAAAQANS41LjEyLWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADdOfJOEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at 107
#111221 14:56:59 server id 1  end_log_pos 203   Query   thread_id=8     exec_time=0     error_code=0
use test/*!*/;
SET TIMESTAMP=1324497419/*!*/;
SET @@session.pseudo_thread_id=8/*!*/;
SET @@session.foreign_key_checks=1, @@session.sql_auto_is_null=0, @@session.unique_checks=1, @@session.autocommit=1/*!*/;
SET @@session.sql_mode=0/*!*/;
SET @@session.auto_increment_increment=1, @@session.auto_increment_offset=1/*!*/;
/*!\C cp850 *//*!*/;
SET @@session.character_set_client=4,@@session.collation_connection=4,@@session.collation_server=8/*!*/;
SET @@session.lc_time_names=0/*!*/;
SET @@session.collation_database=DEFAULT/*!*/;
create table rolandotable (a int)
/*!*/;
# at 203
#111221 14:58:24 server id 1  end_log_pos 271   Query   thread_id=8     exec_time=0     error_code=0
SET TIMESTAMP=1324497504/*!*/;
BEGIN
/*!*/;
# at 271
#111221 14:58:24 server id 1  end_log_pos 369   Query   thread_id=8     exec_time=0     error_code=0
SET TIMESTAMP=1324497504/*!*/;
insert into rolandotable values (1)
/*!*/;
# at 369
#111221 14:58:24 server id 1  end_log_pos 396   Xid = 99
COMMIT/*!*/;
# at 396
#111221 14:58:29 server id 1  end_log_pos 439   Rotate to mysql-bin.000002  pos: 4
DELIMITER ;
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

大多数行都以/*!*/作为条目之间的分隔符。有时,需要在命令之间执行一个特殊指令,例如这个标记:/*!\C cp850 *//*!*/;

该指令\C使用mysql设置一个字符集,用于处理绑定日志中的多字节字符集。我从mysql客户机中的help命令中了解到这一点:

代码语言:javascript
复制
mysql> \?

For information about MySQL products and services, visit:
   http://www.mysql.com/
For developer information, including the MySQL Reference Manual, visit:
   http://dev.mysql.com/
To buy MySQL Enterprise support, training, or other products, visit:
   https://shop.mysql.com/

List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'.
clear     (\c) Clear the current input statement.
connect   (\r) Reconnect to the server. Optional arguments are db and host.
delimiter (\d) Set statement delimiter.
ego       (\G) Send command to mysql server, display result vertically.
exit      (\q) Exit mysql. Same as quit.
go        (\g) Send command to mysql server.
help      (\h) Display this help.
notee     (\t) Don't write into outfile.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.

For server side help, type 'help contents'

mysql>

还有其他指令,如前两行:

代码语言:javascript
复制
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;

第一行的工作时间为MySQL 4.0.19

第二行适用于MySQL 5.0.3

如果运行mysqlbinlog并将输出导入到运行MySQL 4.x的机器上,则将忽略第二行。

我还讨论了mysqldump输出中有关存储过程的这类指令.。这样,如果您将一个MySQL 5.0 mysqldump导入到4.x中,那么创建存储过程的所有命令都会被完全忽略。

这是使用/*!*/的议程

票数 4
EN
页面原文内容由Database Administration提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://dba.stackexchange.com/questions/9556

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档