MySQL帮汉文档的使用
Posted plf-jack
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL帮汉文档的使用相关的知识,希望对你有一定的参考价值。
帮助文档使用
在 mysql 使用过程中,可能经常会遇到以下问题:
- 某个操作语法忘记了,需要快速查找。
- 当前版本上,某个字段类型我们想快速知道它的取值范围?
- 当前版本上,都支持哪些函数?希望有例子能快速入门。
- 当前版本上,是否支持某个功能?
对于上面列出的各种问题,我们可能想到的办法是查找 MySQL 的文档。不错,这些问题在 MySQL 官方文档中都可以很清楚地查到,但是却要耗费大量的时间和精力。 所以对于以上问题,最好的解决办法是使用 MySQL 安装后自带的帮助文档,这样在遇到问 题时就可以方便快捷地进行查询。
按照层次看帮助
如果不知道帮助能够提供些什么,可以用“?contents”命令来显示所有可供查询的的分类, 如下例所示:
mysql> ? 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
对于列出的分类,可以使用“? 类别名称”的方式针对用户感兴趣的内容做进一步的查看。 例如,想看看 MySQL 中都支持哪些数据类型,可以执行“? data types”命令:
mysql> ? data types You asked for help about help category: "Data Types" For more information, type 'help <item>', where <item> is one of the following topics: AUTO_INCREMENT BIGINT BINARY BIT BLOB BLOB DATA TYPE BOOLEAN CHAR CHAR BYTE DATE DATETIME DEC DECIMAL DOUBLE DOUBLE PRECISION ENUM FLOAT INT INTEGER LONGBLOB LONGTEXT MEDIUMBLOB MEDIUMINT MEDIUMTEXT SET DATA TYPE SMALLINT TEXT TIME TIMESTAMP TINYBLOB TINYINT TINYTEXT VARBINARY VARCHAR YEAR DATA TYPE
上面列出的此版本支持的所有数据类型,如果想知道int类型的具体介绍,也可以使用上忙的方法,做进一步的查看:
mysql> ? int Name: 'INT' Description: INT[(M)] [UNSIGNED] [ZEROFILL] A normal-size integer. The signed range is -2147483648 to 2147483647. The unsigned range is 0 to 4294967295. URL: http://dev.mysql.com/doc/refman/5.6/en/numeric-type-overview.html
帮助文档中显示了 int 类型的详细描述。通过这种“? 类别名称”的方式,就可以一层层 地往下查找用户所关心的主题内容。
快速查阅帮助
在实际应用当中,如果需要快速查阅某项语法时,可以使用关键字进行快速查询。例如,想 知道 show 命令都能看些什么东西,可以用如下命令:
mysql> ? 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 SHOW BINLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count] SHOW CHARACTER SET [like_or_where] SHOW COLLATION [like_or_where] SHOW [FULL] COLUMNS FROM tbl_name [FROM db_name] [like_or_where] SHOW CONTRIBUTORS SHOW CREATE DATABASE db_name SHOW CREATE EVENT event_name SHOW CREATE FUNCTION func_name SHOW CREATE PROCEDURE proc_name SHOW CREATE TABLE tbl_name SHOW CREATE TRIGGER trigger_name SHOW CREATE VIEW view_name SHOW DATABASES [like_or_where] SHOW ENGINE engine_name STATUS | MUTEX SHOW [STORAGE] ENGINES SHOW ERRORS [LIMIT [offset,] row_count] SHOW EVENTS SHOW FUNCTION CODE func_name SHOW FUNCTION STATUS [like_or_where] SHOW GRANTS FOR user SHOW INDEX FROM tbl_name [FROM db_name] SHOW MASTER STATUS SHOW OPEN TABLES [FROM db_name] [like_or_where] SHOW PLUGINS SHOW PROCEDURE CODE proc_name SHOW PROCEDURE STATUS [like_or_where] SHOW PRIVILEGES SHOW [FULL] PROCESSLIST SHOW PROFILE [types] [FOR QUERY n] [OFFSET n] [LIMIT n] SHOW PROFILES SHOW RELAYLOG EVENTS [IN 'log_name'] [FROM pos] [LIMIT [offset,] row_count] SHOW SLAVE HOSTS SHOW SLAVE STATUS SHOW [GLOBAL | SESSION] STATUS [like_or_where] SHOW TABLE STATUS [FROM db_name] [like_or_where] SHOW [FULL] TABLES [FROM db_name] [like_or_where] SHOW TRIGGERS [FROM db_name] [like_or_where] SHOW [GLOBAL | SESSION] VARIABLES [like_or_where] SHOW WARNINGS [LIMIT [offset,] row_count] like_or_where: LIKE 'pattern' | WHERE expr If the syntax for a given SHOW statement includes a LIKE 'pattern' part, 'pattern' is a string that can contain the SQL % and _ wildcard characters. The pattern is useful for restricting statement output to matching values. Several SHOW statements also accept a WHERE clause that provides more flexibility in specifying which rows to display. See http://dev.mysql.com/doc/refman/5.6/en/extended-show.html. URL: http://dev.mysql.com/doc/refman/5.6/en/show.html
例如,如果想参看CREATE TABLE 的语法,可以使用以下命令:
mysql> ? create table Name: 'CREATE TABLE' Description: Syntax: CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name (create_definition,...) [table_options] [partition_options] CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name [(create_definition,...)] [table_options] [partition_options] [IGNORE | REPLACE] [AS] query_expression CREATE [TEMPORARY] TABLE [IF NOT EXISTS] tbl_name LIKE old_tbl_name | (LIKE old_tbl_name) create_definition: col_name column_definition | [CONSTRAINT [symbol]] PRIMARY KEY [index_type] (index_col_name,...) [index_option] ... | INDEX|KEY [index_name] [index_type] (index_col_name,...) [index_option] ... | [CONSTRAINT [symbol]] UNIQUE [INDEX|KEY] [index_name] [index_type] (index_col_name,...) [index_option] ... | FULLTEXT|SPATIAL [INDEX|KEY] [index_name] (index_col_name,...) [index_option] ... | [CONSTRAINT [symbol]] FOREIGN KEY [index_name] (index_col_name,...) reference_definition | CHECK (expr) column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value] [AUTO_INCREMENT] [UNIQUE [KEY] | [PRIMARY] KEY] [COMMENT 'string'] [COLUMN_FORMAT FIXED|DYNAMIC|DEFAULT] [STORAGE DISK|MEMORY|DEFAULT] [reference_definition] data_type: BIT[(length)] | TINYINT[(length)] [UNSIGNED] [ZEROFILL] | SMALLINT[(length)] [UNSIGNED] [ZEROFILL] | MEDIUMINT[(length)] [UNSIGNED] [ZEROFILL] | INT[(length)] [UNSIGNED] [ZEROFILL] | INTEGER[(length)] [UNSIGNED] [ZEROFILL] | BIGINT[(length)] [UNSIGNED] [ZEROFILL] | REAL[(length,decimals)] [UNSIGNED] [ZEROFILL] | DOUBLE[(length,decimals)] [UNSIGNED] [ZEROFILL] | FLOAT[(length,decimals)] [UNSIGNED] [ZEROFILL] | DECIMAL[(length[,decimals])] [UNSIGNED] [ZEROFILL] | NUMERIC[(length[,decimals])] [UNSIGNED] [ZEROFILL] | DATE | TIME[(fsp)] | TIMESTAMP[(fsp)] | DATETIME[(fsp)] | YEAR | CHAR[(length)] [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | VARCHAR(length) [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | BINARY[(length)] | VARBINARY(length) | TINYBLOB | BLOB | MEDIUMBLOB | LONGBLOB | TINYTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | TEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | MEDIUMTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | LONGTEXT [BINARY] [CHARACTER SET charset_name] [COLLATE collation_name] | ENUM(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | SET(value1,value2,value3,...) [CHARACTER SET charset_name] [COLLATE collation_name] | spatial_type index_col_name: col_name [(length)] [ASC | DESC] index_type: USING BTREE | HASH index_option: KEY_BLOCK_SIZE [=] value | index_type | WITH PARSER parser_name | COMMENT 'string' reference_definition: REFERENCES tbl_name (index_col_name,...) [MATCH FULL | MATCH PARTIAL | MATCH SIMPLE] [ON DELETE reference_option] [ON UPDATE reference_option] reference_option: RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT table_options: table_option [[,] table_option] ... table_option: ENGINE [=] engine_name | AUTO_INCREMENT [=] value | AVG_ROW_LENGTH [=] value | [DEFAULT] CHARACTER SET [=] charset_name | CHECKSUM [=] 0 | 1 | [DEFAULT] COLLATE [=] collation_name | COMMENT [=] 'string' | CONNECTION [=] 'connect_string' | DATA DIRECTORY [=] 'absolute path to directory' | DELAY_KEY_WRITE [=] 0 | 1 | INDEX DIRECTORY [=] 'absolute path to directory' | INSERT_METHOD [=] NO | FIRST | LAST | KEY_BLOCK_SIZE [=] value | MAX_ROWS [=] value | MIN_ROWS [=] value | PACK_KEYS [=] 0 | 1 | DEFAULT | PASSWORD [=] 'string' | ROW_FORMAT [=] DEFAULT|DYNAMIC|FIXED|COMPRESSED|REDUNDANT|COMPACT | STATS_AUTO_RECALC [=] DEFAULT|0|1 | STATS_PERSISTENT [=] DEFAULT|0|1 | STATS_SAMPLE_PAGES [=] value | TABLESPACE tablespace_name [STORAGE DISK|MEMORY|DEFAULT] | UNION [=] (tbl_name[,tbl_name]...) partition_options: PARTITION BY [LINEAR] HASH(expr) | [LINEAR] KEY [ALGORITHM=1|2] (column_list) | RANGE(expr) | COLUMNS(column_list) | LIST(expr) | COLUMNS(column_list) [PARTITIONS num] [SUBPARTITION BY [LINEAR] HASH(expr) | [LINEAR] KEY [ALGORITHM=1|2] (column_list) [SUBPARTITIONS num] ] [(partition_definition [, partition_definition] ...)] partition_definition: PARTITION partition_name [VALUES LESS THAN (expr | value_list) | MAXVALUE | IN (value_list)] [[STORAGE] ENGINE [=] engine_name] [COMMENT [=] 'comment_text' ] [DATA DIRECTORY [=] 'data_dir'] [INDEX DIRECTORY [=] 'index_dir'] [MAX_ROWS [=] max_number_of_rows] [MIN_ROWS [=] min_number_of_rows] [TABLESPACE [=] tablespace_name] [NODEGROUP [=] node_group_id] [(subpartition_definition [, subpartition_definition] ...)] subpartition_definition: SUBPARTITION logical_name [[STORAGE] ENGINE [=] engine_name] [COMMENT [=] 'comment_text' ] [DATA DIRECTORY [=] 'data_dir'] [INDEX DIRECTORY [=] 'index_dir'] [MAX_ROWS [=] max_number_of_rows] [MIN_ROWS [=] min_number_of_rows] [TABLESPACE [=] tablespace_name] [NODEGROUP [=] node_group_id] query_expression: SELECT ... (Some valid select or union statement) CREATE TABLE creates a table with the given name. You must have the CREATE privilege for the table. By default, tables are created in the default database, using the InnoDB storage engine. An error occurs if the table exists, if there is no default database, or if the database does not exist. For information about the physical representation of a table, see http://dev.mysql.com/doc/refman/5.6/en/create-table-files.html. URL: http://dev.mysql.com/doc/refman/5.6/en/create-table.html
常用的网络资源
http://dev.mysql.com/downloads/是MySQL 的官方网站,可以下载到各个版本的 MySQL 以及 相关客户端开发工具等。
http://dev.mysql.com/doc/提供了目前最权威的 MySQL 数据库及工具的在线手册。
http://bugs.mysql.com/这里可以查看到MySQL 已经发布的bug 列表,或者向MySQL提交 bug 报告。
http://www.mysql.com/news-and-events/newsletter/通常会发布各种关于MySQL的最新消息
小结:
本章简单地介绍了 SQL 语句的基本分类 DML/DDL/DCL,并对每一种分类下的常用 SQL 的用 法进行了举例说明。MySQL 在标准 SQL 的基础上进行了很多扩展,本章对常用的一些语法 做了简单介绍,更详细的说明,读者可以参考 MySQL 的帮助或者官方文档。在本章的最后, 还介绍了用户应如何使用 MySQL 中的帮助文档,以便快速查找各种语法定义
以上是关于MySQL帮汉文档的使用的主要内容,如果未能解决你的问题,请参考以下文章
在 C# 中使用 mysql 文档存储(Nosql)中的日期字段进行过滤