MySQL經常使用SQL

終端登錄系統

[root@host]# mysql -u root -p   
Enter password:******  # 登陸後進入終端

建立數據庫

CREATE DATABASE 數據庫名;

查看數據庫

1.查看全部數據庫mysql

SHOW DATABASES;

模糊查詢

show databases like 't%';

刪除數據庫

drop database <數據庫名>;

執行以上刪除數據庫命令後,會出現一個提示框,來確認是否真的刪除數據庫:sql

Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
Do you really want to drop the ‘RUNOOB’ database [y/N] y
Database 「RUNOOB」 dropped

選擇數據庫

1.在登錄後選擇shell

use 數據庫名;

2.在登錄時選擇數據庫

shell> mysql -h host -u user -p 數據庫名
Enter password: ********

經常使用SQL

order by 排序

1.單字段降序:code

select * from table order by id desc;

2.單字段升序:排序

select * from table order by id asc;

3.多字段排序:table

select * from table order by id desc,name desc;

多字字段排序只須要添加多個排序條件,而且每一個排序的條件以前用逗號分開。class

order by id desc,name desc; 表示先按照id降序排序,再按照name降序排序。登錄

同理:select

order by id desc,name asc; 表示先按照id降序排序,再按照name升序排序。

相關文章
相關標籤/搜索