|
2019-05-17
-u // 指定用户名 -p // 指定密码 -P // 指定端口 -h // 指定主机名
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 ( ) 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 ( ) 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. 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. resetconnection(x) Clean session context. For server side help, type 'help contents'
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | sys | +--------------------+ 4 rows in set (0.01 sec)
mysql> use [db_name]; Database changed
mysql> show tables; mysql> show tables from [db_name]; // 查询指定数据库中的所有可用表 +-------------------+ | Tables_in_acgfate | +-------------------+ | accounts | | users | +-------------------+ 2 rows in set (0.01 sec)
mysql> show columns from [table]; +------------+------------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+------------------+------+-----+---------+----------------+ | id | bigint unsigned | NO | PRI | NULL | auto_increment | | created_at | datetime(3) | YES | | NULL | | | updated_at | datetime(3) | YES | | NULL | | | deleted_at | datetime(3) | YES | MUL | NULL | | | username | longtext | YES | | NULL | | | password | longtext | YES | | NULL | | | nickname | longtext | YES | | NULL | | | mail | longtext | YES | | NULL | | | avatar | longtext | YES | | NULL | | | gender | longtext | YES | | NULL | | | level | tinyint unsigned | YES | | NULL | | | join_time | datetime(3) | YES | | NULL | | | silence | tinyint(1) | YES | | NULL | | +------------+------------------+------+-----+---------+----------------+ 13 rows in set (0.01 sec)
查询 简单查询 按列查询
SELECT [column] FROM [table]; SELECT [column1], [column2] FROM [table]; SELECT * FROM [table];
SELECT DISTINCT [column] FROM [table]
city |
provience |
---|---|
A1 |
LA |
A2 |
LA |
A1 |
LB |
使用LIMIT子句可以限定查询的范围,而不是查询整个表的记录:
SELECT [column] FROM [table] LIMIT 5; // 查询前5行 SELECT [column] FROM [table] LIMIT 5, 5 // 查询从第6行开始的5条记录
SELECT [table].[column] FROM [table]
按指定列排序
SELECT [column1] FROM [table] ORDER BY [column2] SELECT [column1] FROM [table] ORDER BY [column2] DESC // 按降序排序
SELECT [column1] FROM [table] ORDER BY [column2], [column3] SELECT [column1] FROM [table] ORDER BY [column2] DESC, [column3]
编辑:航网科技 来源:腾讯云 本文版权归原作者所有 转载请注明出处
微信扫一扫咨询客服
全国免费服务热线
0755-36300002