This slide is based on Jeffrey D. Ullman's work, which can be download from his website.
References: 刘增杰、张少军 《MySQL 5.5 从零开始学》
mysqlshow.exe > D:\tmp\mysqlshow.txt or mysqlshow.exe >> D:\tmp\mysqlshow.txt
C:\wamp\bin\mysql\mysql5.5.24\bin\mysqlshow +--------------------+ | Databases | +--------------------+ | information_schema | | test | | test_4 | | test_bar | | test_products | | test_ships | +--------------------+
C:\wamp\bin\mysql\mysql5.5.24\bin\mysqlshow test_bar Database: test_bar +-----------+ | Tables | +-----------+ | bars | | bars2 | | beers | | drinkers | | frequents | | likes | | sells | | synergy | +-----------+
显示 test_bar 数据库中的 beers 表的结构信息, 注意不能写成 test_bar.beers, 要用空格隔开数据库和表
C:\wamp\bin\mysql\mysql5.5.24\bin\mysqlshow test_bar beers Database: test_bar Table: beers +-------+-------------+----------------+------+-----+---------+-------+---------------------------------+---------+ | Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment | +-------+-------------+----------------+------+-----+---------+-------+---------------------------------+---------+ | name | varchar(20) | gbk_chinese_ci | YES | UNI | | | select,insert,update,references | | | manf | varchar(50) | gbk_chinese_ci | YES | | | | select,insert,update,references | | +-------+-------------+----------------+------+-----+---------+-------+---------------------------------+---------+
perror Ver 2.11, for Win32 (x86) This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL license Print a description for a system error code or a MySQL error code. If you want to get the error for a negative error code, you should use -- before the first error code to tell perror that there was no more options. Usage: perror [OPTIONS] [ERRORCODE [ERRORCODE...]] -?, --help Displays this help and exits. -I, --info Synonym for --help. -s, --silent Only print the error message. -v, --verbose Print error code and message (default). (Defaults to on; use --skip-verbose to disable.) -V, --version Displays version information and exits. Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- verbose TRUE
我们首先在 mysql 交互终端故意输错一个命令, 比如
mysql> show database test_bar; 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 'database test_bar' at line 1
然后使用 perror 查看错误代码 1064.
C:\wamp\bin\mysql\mysql5.5.24\bin\perror 1064 MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d Win32 error code 1064: 当处理控制请求时,在服务中发生异常。
如果加上参数
%s near '%-.80s' at line %d 当处理控制请求时,在服务中发生异常
C:\wamp\bin\mysql\mysql5.5.24\bin\perror 1064 (42000) or perror 1064 [42000]
MySQL error code 1064 (ER_PARSE_ERROR): %s near '%-.80s' at line %d Win32 error code 1064: 当处理控制请求时,在服务中发生异常。 OS error code 0: No error Win32 error code 0: 操作成功完成。
SQL 命令
Usage: mysqlimport.exe [OPTIONS] database textfile...
mysqlimport.exe Ver 3.7 Distrib 5.5.24, for Win32 (x86) Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Loads tables from text files in various formats. The base name of the text file must be the name of the table that should be used. If one uses sockets to connect to the MySQL server, the server will open and read the text file directly. In other cases the client will open the text file. The SQL command 'LOAD DATA INFILE' is used to import the rows. Usage: mysqlimport.exe [OPTIONS] database textfile... Default options are read from the following files in the given order: C:\Windows\my.ini C:\Windows\my.cnf C:\my.ini C:\my.cnf C:\wamp\bin\mysql\mysql5.5.24\my.ini C:\wamp\bin\mysql\mysql5.5.24\my.cnf The following groups are read: mysqlimport client The following options may be given as the first argument: --print-defaults Print the program argument list and exit. --no-defaults Don't read default options from any option file. --defaults-file=# Only read default options from the given file #. --defaults-extra-file=# Read this file after the global files are read. --character-sets-dir=name Directory for character set files. --default-character-set=name Set the default character set. -c, --columns=name Use only these columns to import the data to. Give the column names in a comma separated list. This is same as giving columns to LOAD DATA INFILE. -C, --compress Use compression in server/client protocol. -#, --debug[=name] Output debug log. Often this is 'd:t:o,filename'. --debug-check Check memory and open file usage at exit. --debug-info Print some debug info at exit. --default-auth=name Default authentication client-side plugin to use. -d, --delete First delete all rows from table. --fields-terminated-by=name Fields in the input file are terminated by the given string. --fields-enclosed-by=name Fields in the import file are enclosed by the given character. --fields-optionally-enclosed-by=name Fields in the input file are optionally enclosed by the given character. --fields-escaped-by=name Fields in the input file are escaped by the given character. -f, --force Continue even if we get an SQL error. -?, --help Displays this help and exits. -h, --host=name Connect to host. -i, --ignore If duplicate unique key was found, keep old row. --ignore-lines=# Ignore first n lines of data infile. --lines-terminated-by=name Lines in the input file are terminated by the given string. -L, --local Read all files through the client. -l, --lock-tables Lock all tables for write (this disables threads). --low-priority Use LOW_PRIORITY when updating the table. -p, --password[=name] Password to use when connecting to server. If password is not given it's asked from the tty. -W, --pipe Use named pipes to connect to server. --plugin-dir=name Directory for client-side plugins. -P, --port=# Port number to use for connection or 0 for default to, in order of preference, my.cnf, $MYSQL_TCP_PORT, /etc/services, built-in default (3306). --protocol=name The protocol to use for connection (tcp, socket, pipe, memory). -r, --replace If duplicate unique key was found, replace old row. --shared-memory-base-name=name Base name of shared memory. -s, --silent Be more silent. -S, --socket=name The socket file to use for connection. --ssl Enable SSL for connection (automatically enabled with other flags). --ssl-ca=name CA file in PEM format (check OpenSSL docs, implies --ssl). --ssl-capath=name CA directory (check OpenSSL docs, implies --ssl). --ssl-cert=name X509 cert in PEM format (implies --ssl). --ssl-cipher=name SSL cipher to use (implies --ssl). --ssl-key=name X509 key in PEM format (implies --ssl). --ssl-verify-server-cert Verify server's "Common Name" in its cert against hostname used when connecting. This option is disabled by default. --use-threads=# Load files in parallel. The argument is the number of threads to use for loading data. -u, --user=name User for login if not current user. -v, --verbose Print info about the various stages. -V, --version Output version information and exit. Variables (--variable-name=value) and boolean options {FALSE|TRUE} Value (after reading options) --------------------------------- ---------------------------------------- character-sets-dir (No default value) default-character-set utf8 columns (No default value) compress FALSE debug-check FALSE debug-info FALSE default-auth (No default value) delete FALSE fields-terminated-by (No default value) fields-enclosed-by (No default value) fields-optionally-enclosed-by (No default value) fields-escaped-by (No default value) force FALSE host (No default value) ignore FALSE ignore-lines 0 lines-terminated-by (No default value) local FALSE lock-tables FALSE low-priority FALSE plugin-dir (No default value) port 3306 replace FALSE shared-memory-base-name (No default value) silent FALSE socket /tmp/mysql.sock ssl FALSE ssl-ca (No default value) ssl-capath (No default value) ssl-cert (No default value) ssl-cipher (No default value) ssl-key (No default value) ssl-verify-server-cert FALSE use-threads 0 user (No default value) verbose FALSE
mysql> use test;
mysql> CREATE TABLE tmp1( -> x TINYINT, -> y SMALLINT, -> z MEDIUMINT, -> m INT, -> n BIGINT -> );
mysql> desc tmp1; +-------+--------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+--------------+------+-----+---------+-------+ | x | tinyint(4) | YES | | NULL | | | y | smallint(6) | YES | | NULL | | | z | mediumint(9) | YES | | NULL | | | m | int(11) | YES | | NULL | | | n | bigint(20) | YES | | NULL | | +-------+--------------+------+-----+---------+-------+ 5 rows in set (0.00 sec)
delete from alg_users where username='horny';