Mysql的基础操作语句

对数据库的操作:

1.连接数据库:mysql -u root -p;

2.查询数据库:show databases;

3.创建数据库:create database 数据库名;

4.删除数据库:drop database 数据库名;

5.选择数据库:use 数据库名;

对数据表的操作:

1.创建数据表:create table 表名(列名 数据类型,。。。。。。,列名 数据类型);

2.删除数据表:deop table 表名;

3.插入数据:insert into 表名 values(value1,value2,。。。,valueN);如果数据类型是字符型,需要用双引号。

4.查询数据表:两种方式:

select * from 表名:

select field1,field2,。。。fieldN from 表名;

5.查看所有表:show tables;

6.查询某条件下的所有数据:select * from  表名 where 字段1=值1 and 字段2=值2 and 。。。and 字段n=值n;

或者select * from  表名 where 字段1=值1 or 字段2=值2 or 。。。or 字段n=值n;

7.由低到高排序:select * from 表名 order by 字段x asc;

8.由高到低排序:select * from 表名 order by 字段x desc;

9.按某条件排序:select * from 表名 where 字段x=值x order by 字段x asc (desc);

10.删除表中的数据:delete from 表名 where 字段x=值x;

posted @ 2019-06-21 10:44  大壞狐狸  阅读(195)  评论(0)    收藏  举报