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升序排序。

相关文章
相关标签/搜索