命令行下可以使用的各种命令解析(转)

mysql -u root -p
进入到mysql客户端应用程序mysql,通过它可以管理数据库
,访问数据库,执行SQL语句等等。

1. 获取帮助
mysql>help或者/?

2. 将在mysql>下输入的内容输出到文件中,使用
mysql>tee filename或者T filename
mysql会提示你已经logging to file 'filename'
这样在mysql>下输入的命令及输出结果就会都保存到filename文件中
如果想取消挂载,输入 notee或者t
mysql会提示outfile disabled

在进入mysql之前,也可以通过选项--tee或者--no-tee挂载外部文件或者取消
mysql -u root -p --tee outfile
或者
mysql -u root -p --no-tee

3.
mysql>tee mysql_help.txt
将输出挂载到mysql_help.txt文件上
输入mysql>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 Network 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'.
help (h) Display this help.
clear (c) Clear command.
connect (r) Reconnect to the server. Optional arguments are db and host.
delimiter (d) Set statement delimiter. NOTE: Takes the rest of the line as new delimiter.
ego (G) Send command to mysql server, display result vertically.

go (g) Send command to mysql server.
tee (T) Set outfile [to_outfile]. Append everything into given outfile.
notee (t) Don't write into outfile.
print (p) Print current command.
prompt (R) Change your mysql prompt.

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.

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.

exit (q) Exit mysql. Same as quit.
quit (q) Quit mysql.

For server side help, type 'help contents'

4. 常用命令示例

a. mysql>?或者help

b. mysql> show databases G
*************************** 1. row ***************************
Database: information_schema
*************************** 2. row ***************************
Database: broker
*************************** 3. row ***************************
Database: gene2pubmed
*************************** 4. row ***************************
Database: mysql
*************************** 5. row ***************************
Database: test
5 rows in set (0.00 sec)

c.
mysql>tee [outfile] 不输入outfile,则使用上次挂载的文件
mysql>notee 取消挂载

d. mysql>status 显示状态信息

e. mysql>use database_name

f.
定义一个文件sql_script,内容为sql语句,使用source执行文件中的sql script
如sql_script文件中保存show databases;
mysql>source sql_script
会显示sql_script中show databases;执行的结果

此外注意,获取server side的帮助可以使用 help contents命令

mysql>下输入help contents查询各种帮助。
当要完成某项功能的时候,又不知道该用哪个命令的时候可以在mysql>下输入help contents查询帮助文档,了解各个命令的功能。

2.
mysql>help contents获取查询结果

mysql> help contents
You asked for help about help category: "Contents"
For more information, type 'help ', where is one of the following
categories:
Account Management
Administration
Data Definition
Data Manipulation
Data Types
Functions
Functions and Modifiers for Use with GROUP BY
Geographic Features
Language Structure
Storage Engines
Stored Routines
Table Maintenance
Transactions
Triggers

//如下highlight的命令为常用命令,通过help item_name可以查看其具体功能

帐号管理
mysql> help account management
You asked for help about help category: " Account Management"
For more information, type 'help ', where is one of the following
topics:
CREATE USER
//创建一个用户
DROP USER
//删除一个用户
GRANT
//为用户赋予权限
RENAME USER
REVOKE
SET PASSWORD
//为某个用户设置帐户

数据库管理
mysql> help administration
You asked for help about help category: " Administration"
For more information, type 'help ', where is one of the following
topics:
DESCRIBE
//描述信息,可以用它输出数据表结构,help DESCRIBE查看更多信息
FLUSH QUERY CACHE
HELP COMMAND
HELP STATEMENT

数据定义
mysql> help data definition
You asked for help about help category: "Data Definition"
For more information, type 'help ', where is one of the following
topics:
ALTER DATABASE
//修改数据库
ALTER TABLE
//修改数据表结构
ALTER VIEW
CONSTRAINT
CREATE DATABASE
//创建一个数据库
CREATE INDEX
//创建一个索引,help create index了解更多
CREATE TABLE
//创建一个数据表
CREATE VIEW
DROP DATABASE
DROP INDEX
DROP TABLE
DROP VIEW
MERGE
RENAME TABLE

数据操作
mysql> help data manipulation
You asked for help about help category: " Data Manipulation"
For more information, type 'help ', where is one of the following
topics:
CACHE INDEX
CHANGE MASTER TO
DEALLOCATE PREPARE
DELETE
DO
DUAL
EXECUTE STATEMENT
EXPLAIN

Syntax:
EXPLAIN tbl_name
//等同于DESCRIBE table_name,显示数据表定义结构
Or:
EXPLAIN [EXTENDED] SELECT select_options
//显示MySQL执行SELECT语句的细节,方便采取优化策略

The EXPLAIN statement can be used either as a synonym for DESCRIBE or as a way to obtain information about how MySQL executes a SELECT statement:
o EXPLAIN tbl_name is synonymous with DESCRIBE tbl_name or SHOW COLUMNS FROM tbl_name.
o When you precede a SELECT statement with the keyword EXPLAIN, MySQL displays information from the optimizer about the query execution plan. That is, MySQL explains how it would process the SELECT, including information about how tables are joined and in which order.

FLUSH
HANDLER
INSERT
//插入数据
INSERT DELAYED
INSERT SELECT
//使用INSERT SELECT可以将从一个或多个数据表SELECT的结果插入到另一个表格中

JOIN
//MySQL中的多表连接操作,详细情况help join

KILL
//客户端连接到mysql的server即mysqld,都是独立的线程thread,通过show processlist可以查看连接到mysqld server的各个线程的id,通过kill可以结束当前连接(CONNECTION)或者查询(QUERY)的线程

LOAD DATA
//从指定目录导入数据,help load data了解更多信息

LOAD DATA FROM MASTER
LOAD INDEX
LOAD TABLE FROM MASTER
PREPARE
PURGE MASTER LOGS
REPLACE INTO
RESET
RESET MASTER
RESET SLAVE
SELECT
//SELECT除了用于从数据库中检索满足所定义条件的制定列之外,还可以返回和任何table都无关的数据信息,如SELECT 1+1

SET

SET GLOBAL SQL_SLAVE_SKIP_COUNTER
SET SQL_LOG_BIN

SHOW has many forms that provide information about databases, tables,
columns, or status information about the server. This section describes
//MySQL的SHOW功能很强大,通过help show可以查看更加详细的功能,显示数据库,数据表以及列,以及Server的状态信息
SHOW
SHOW BINARY LOGS
SHOW BINLOG EVENTS
SHOW CHARACTER SET
SHOW COLLATION
SHOW COLUMNS
SHOW CREATE DATABASE
SHOW CREATE PROCEDURE
SHOW CREATE TABLE
SHOW CREATE VIEW
SHOW DATABASES
SHOW ENGINE
SHOW ENGINES
SHOW ERRORS
SHOW GRANTS
SHOW INDEX
SHOW INNODB STATUS
SHOW LOGS
SHOW MASTER STATUS
SHOW MUTEX STATUS
SHOW OPEN TABLES
SHOW PRIVILEGES
SHOW PROCEDURE CODE
SHOW PROCEDURE STATUS
SHOW PROCESSLIST
SHOW PROFILES
SHOW SLAVE HOSTS
SHOW SLAVE STATUS
SHOW STATUS
SHOW TABLE STATUS
SHOW TABLES
SHOW TRIGGERS
SHOW VARIABLES
SHOW WARNINGS
START SLAVE
STOP SLAVE
TRUNCATE TABLE
UNION
UPDATE

MySQL支持的数据类型
mysql> help data types
You asked for help about help category: "Data Types"
For more information, type 'help ', where 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

函数
mysql> help functions
You asked for help about help category: " Functions"
For more information, type 'help ', where is one of the following
topics:
CREATE FUNCTION
DROP FUNCTION
PROCEDURE ANALYSE
categories:
Bit Functions
Comparison operators
Control flow functions
Date and Time Functions
Encryption Functions
Information Functions
Logical operators
Miscellaneous Functions
Numeric Functions
String Functions

[@more@]

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/6456/viewspace-1017883/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/6456/viewspace-1017883/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值