Mysql help命令(帮助信息)中文注解
程序员文章站
2024-03-01 09:54:10
在开发或测试环境在碰到mysql相关故障时,大多数朋友可能会通过论坛发帖,qq群讨论方式来获取帮助。该方式是获取帮助的有效途径之一。然而如果在生产环境,在没有网络的环境下,...
在开发或测试环境在碰到mysql相关故障时,大多数朋友可能会通过论坛发帖,qq群讨论方式来获取帮助。该方式是获取帮助的有效途径之一。然而如果在生产环境,在没有网络的环境下,这些方式就无助于问题的解决。无论何种数据库,从官方网站获取帮助是最直接最有效的方式。其次没有网络的环境下,我们可以通过mysql客户端工具自带的帮助信息来解决问题。
1)mysql官方手册
和oracle官方文档一下,mysql官方手册是获取mysql帮助最直接最效的方式。该手册包含很多个部分,比如有关sql的语法,mysql安装方式,mysql的系统变量,状态变量,命令行的常用工具,数据库的管等等。总之是一个mysql数据相关的大合集。支持pdf及html方式下载。
下载位置:
2)mysql客户端工具自带的帮助
获取mysql有关的帮助信息,直接在mysql提示符下输入help即可获得有关在mysql客户端相关的帮助信息。 这个方式与oracle sql*plus下的help 是类似的。 mysql> help 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. --重新连接,通常用于被剔除或异常断开后重新连接,sql*plus下也有这样一个connect命令 delimiter (\d) set statement delimiter. --设置命令终止符,缺省为;,比如我们可以设定为/来表示语句结束 edit (\e) edit command with $editor. --编辑缓冲区的上一条sql语句到文件,缺省调用vi,文件会放在/tmp路径下 ego (\g) send command to mysql server, display result vertically. --控制结果显示为垂直显示 exit (\q) exit mysql. same as quit. --退出mysql go (\g) send command to mysql server. --发送命令到mysql服务 help (\h) display this help. nopager (\n) disable pager, print to stdout. --关闭页设置,打印到标准输出 notee (\t) don't write into outfile. --关闭输出到文件 pager (\p) set pager [to_pager]. print the query results via pager. --设置pager方式,可以设置为调用more,less等等,主要是用于分页显示 print (\p) print current command. prompt (\r) change your mysql prompt. --改变mysql的提示符 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. --获得状态信息 system (\!) execute a system shell command. --执行系统命令 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' --注意这里的描述help contents将获得服务器端的相关帮助信息 --演示部分,演示常用命令 --connect命令 mysql> connect chardb localhost; reading table information for completion of table and column names you can turn off this feature to get a quicker startup with -a connection id: 5 current database: chardb --设置分页,在多余一个页面显示时会不停的翻滚,用该命令可以设置分页,设置为调用系统命令 mysql> pager more --设置为more方式 pager set to 'more' mysql> select table_name,table_type,engine from information_schema.tables; --该查询会超出一屏显示后按空格键会自动翻滚到下一屏 mysql> pager tail -5; --设置输出尾部5行 pager set to 'tail -5' mysql> select table_name,table_type,engine from information_schema.tables; | setup_timers | base table | performance_schema | | threads | base table | performance_schema | | animals | base table | innodb | | shop | base table | innodb | +----------------------------------------------+-------------+--------------------+ 92 rows in set (0.02 sec) mysql> pager; --查看当前的pager设置 pager set to 'tail -5' mysql> nopager; --切换到标准(缺省)pager方式 pager set to stdout --tee命令,输出日志文件 mysql> tee /tmp/query.log --开启输出到文件,相当与sql*plus下的spool logging to file '/tmp/query.log' mysql> select table_name,table_type,engine from information_schema.tables; +----------------------------------------------+-------------+--------------------+ | table_name | table_type | engine | +----------------------------------------------+-------------+--------------------+ | character_sets | system view | memory | | collations | system view | memory | ............. mysql> notee; --关闭输出到文件,相当于sql*plus下的spool off outfile disabled. mysql> system tail /tmp/query.log --查看输出的日志文件 | setup_consumers | base table | performance_schema | | setup_instruments | base table | performance_schema | | setup_timers | base table | performance_schema | | threads | base table | performance_schema | | animals | base table | innodb | | shop | base table | innodb | +----------------------------------------------+-------------+--------------------+ 92 rows in set (0.02 sec) --改变mysql提示符 mysql> prompt sessiona> prompt set to 'sessiona> ' --恢复到缺省提示符 sessiona> prompt; returning to default prompt of mysql> --执行sql脚本文件 mysql> system more query.sql --注意,此时为当前目录 use chardb select * from tb_isam; mysql> source query.sql reading table information for completion of table and column names you can turn off this feature to get a quicker startup with -a database changed +------+-------+ | id | value | +------+-------+ | 1 | a | | 2 | b | | 3 | c | | 4 | f | +------+-------+ 4 rows in set (0.00 sec) --获取状态信息 mysql> status; -------------- mysql ver 14.14 distrib 5.5.37, for linux (x86_64) using readline 5.1 connection id: 6 current database: chardb current user: root@localhost ssl: not in use current pager: less using outfile: '' using delimiter: ; server version: 5.5.37-log mysql community server (gpl) protocol version: 10 connection: localhost via unix socket server characterset: latin1 db characterset: utf8 client characterset: latin1 conn. characterset: latin1 unix socket: /var/lib/mysql/mysql.sock uptime: 3 hours 10 min 59 sec threads: 1 questions: 97 slow queries: 0 opens: 313 flush tables: 1 open tables: 51 queries per second avg: 0.008 -------------- --修改客户端字符集 mysql> charset gbk; charset changed mysql> \s -------------- mysql ver 14.14 distrib 5.5.37, for linux (x86_64) using readline 5.1 connection id: 6 current database: chardb current user: root@localhost ssl: not in use current pager: less using outfile: '' using delimiter: ; server version: 5.5.37-log mysql community server (gpl) protocol version: 10 connection: localhost via unix socket server characterset: latin1 db characterset: utf8 client characterset: gbk ---客户端和conn端字符集都变成gbk了。 conn. characterset: gbk unix socket: /var/lib/mysql/mysql.sock uptime: 3 hours 13 min 33 sec threads: 1 questions: 105 slow queries: 0 opens: 313 flush tables: 1 open tables: 51 queries per second avg: 0.009 -------------- mysql> warnings; show warnings enabled. mysql> selecs 1; error 1064 (42000): you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'selecs 1' at line 1 mysql> show warnings; +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | level | code | message | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | error | 1064 | you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'selecs 1' at line 1 | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> show errors; +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | level | code | message | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ | error | 1064 | you have an error in your sql syntax; check the manual that corresponds to your mysql server version for the right syntax to use near 'selecs 1' at line 1 | +-------+------+------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec) mysql> nowarning; show warnings disabled.
3、服务端的相关帮助
--获取服务器管理相关的帮助,输入help contents mysql> help contents; you asked for help about help category: "contents" for more information, type 'help <item>', where <item> is one of the following categories: account management administration compound statements data definition data manipulation data types functions functions and modifiers for use with group by geographic features help metadata language structure plugins procedures storage engines table maintenance transactions user-defined functions utility --要查询那一个部分的内容,直接输入help + 内容,如下 mysql> help administration; you asked for help about help category: "administration" for more information, type 'help <item>', where <item> is one of the following topics: binlog cache index flush flush query cache help command kill .......... --接下来,我们查看administration部分下的flush命令用法,直接输入help flush;即可 mysql> help flush; name: 'flush' description: syntax: flush [no_write_to_binlog | local] flush_option [, flush_option] ... the flush statement has several variant forms that clear or reload various internal caches, flush tables, or acquire locks. to execute flush, you must have the reload privilege. specific flush options might require additional privileges, as described later. --查看cache index的帮助信息 mysql> help cache index; name: 'cache index' description: syntax: cache index tbl_index_list [, tbl_index_list] ... [partition (partition_list | all)] in key_cache_name tbl_index_list: tbl_name [[index|key] (index_name[, index_name] ...)] partition_list: partition_name[, partition_name][, ...] ........................ --总结,即通过逐级help的方式即可获得与其主题相关的详细信息。 --author: leshami --blog: <a target="_blank" href="http://blog.csdn.net/leshami">http://blog.csdn.net/leshami </a>--比较常用的show 命令,通常查看系统变量,状态变量等 mysql> help show; name: 'show' description: show has many forms that provide information about databases, tables, columns, or status information about the server. this section describes those following: show authors show {binary | master} logs --设置系统变量,用set 命令 mysql> help set; name: 'set' description: syntax: set variable_assignment [, variable_assignment] ... variable_assignment: user_var_name = expr | [global | session] system_var_name = expr | [@@global. | @@session. | @@]system_var_name = expr the set statement assigns values to different types of variables that affect the operation of the server or your client. older versions of mysql employed set option, but this syntax is deprecated in favor of set without option. url: http://dev.mysql.com/doc/refman/5.5/en/set-statement.html