使用mysql:命令行输入mysql直接进入mysql,没有进去的话,请确定已安装mysql并且已开启mysql服务,以某用户登录mysql请使用mysql -u root -p 123456(你的密码)
show databases;进入数据库查看有什么数据库
create database test default charset utf8 collate utf8_general_ci; 如果想创建数据库,并设置默认字符为utf8,排序顺序为utf8_general_ci即大小写不敏感
use test; 对test数据库进行操作,选择某一数据库后才能进行后面的操作
create table students (id int ,name varchar(20));创建一个表,表里有id和name
show tables;查看数据库有哪些表
show columns from test; 或者describe test;查看表有的属性信息。
select id,name from student;或者select * from student;查看id和name的值
select distinct id from student;如果id有重复的,只显示其中一个
select id,name from student limit 3;只显示前三个结果
select id,name from student limit 2,3;显示从第三个开始数三个的结果(第一行是0)
select id,name from student order by id desc;根据id大小排序,desc倒序,asc顺序(默认是升序)
select id,name from student order by id desc,name;先根据id大小倒序排序,再根据名字排
select * from student where id=14;
select * from student where id between 2 and 10;
select * from student where name is null;(name赋值时是赋值为null,不是其它)
select * from student where name='bp' and id =14;
select * from student where id in (1,14);打印id是1和14的
select * from student where id not in (1,14);打印id不是1和14的
select * from student where name like 'bp%';打印名字以bp开头的信息,只能以bp开头,前面多个字母都不行,还有%a%,s%e之类的用法,%代表0个或者一个,或者多个字符
select * from student where name like 'bp_';跟%差不多,只是_只能匹配一个字符,而不是多个字符