修改密码:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpass');
查询数据库:Show databases;
![](https://img.haomeiwen.com/i3912830/690d03c87263d64e.png)
创建数据库(helloworld):create database helloworld;
![](https://img.haomeiwen.com/i3912830/584d562ebc823184.png)
使用数据库(helloworld):use helloworld;
![](https://img.haomeiwen.com/i3912830/348e46449c275e58.png)
创建表格:create table mytable();
create table mytable(//创建表名为mytable
id int auto_increment,//auto_increment为自动增长
username varchar(30),
password varchar(30),
primary key(id)//设置主键为id
);
![](https://img.haomeiwen.com/i3912830/617343f8b02ffa0e.png)
查看表结构:desc mytable;
![](https://img.haomeiwen.com/i3912830/924fe1b6394f0e02.png)
删除表:drop table mytable;
![](https://img.haomeiwen.com/i3912830/aa8a5284c9bcc657.png)
插入数据:insert into mytable(要插入到哪列) values(插入的值)
insert into mytable(username,password) values('hero','1234');
![](https://img.haomeiwen.com/i3912830/9b94a95bda7b97a2.png)
简单查询列表:select * from mytable;
![](https://img.haomeiwen.com/i3912830/7ec1de7b389196d9.png)
更新数据:
//更新id=1的username为China
update mytable set username='China' where id=1;
![](https://img.haomeiwen.com/i3912830/23a5322437f92c88.png)
修改用户名和密码用逗号隔开就OK
![](https://img.haomeiwen.com/i3912830/3ac9b89e8bbcc665.png)
删除指定Id的数据
delete from mytable where id=1;
![](https://img.haomeiwen.com/i3912830/1861f7f5eabe0648.png)
查询前4条数据
select * from mytable limit 4;
![](https://img.haomeiwen.com/i3912830/108a345bc4cc87ee.png)
查询指定的某几条数据
//从第一条后面开始查找,查询后面的三条
select * from mytable limit 1,3;
![](https://img.haomeiwen.com/i3912830/cb537e3dae7f9e69.png)
查询制定id的用户名
select username from mytable where id=5;
![](https://img.haomeiwen.com/i3912830/37cc10bebcb06a75.png)
根据id排序
select * from mytable order by id desc;//order表示排序 desc表示反向
![](https://img.haomeiwen.com/i3912830/f197a7c211c0c040.png)
转换列表顺序,并修改列表名。
select password Password,username Name from mytable;
![](https://img.haomeiwen.com/i3912830/5f3b7ea6e917797c.png)
四舍五入:round()
select round(4.44,1);//四舍五入,保留后小数一位
![](https://img.haomeiwen.com/i3912830/1d2832ed095ba4fb.png)
直接舍去,直接入
select floor(4.6);//直接舍去
select ceiling(4.2);//直接入
![](https://img.haomeiwen.com/i3912830/0f76324e3a16a27b.png)
去重(distinct)
select distinct username as Name from mytable;
//去除username里面重复的数据并且更改列名
![](https://img.haomeiwen.com/i3912830/ee536e490569790e.png)
字符串操作
concat
left
length
reverse
replace
date_format %m %b %d %y %Y %T %f
(详情:http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format)
get_format(datetime,'EUR' 'ISO' 'USA')
dayofweek
quarter
week
monthname
distinct(去重)
where条件
1,数字 > < = >= <= <>
2,字符串 = '' > < = >= <= <> !=
逻辑操作
is 仅用is null或is not null
and or not
and 优先级> or
范围判断
in (not in)
between (not between) 示例:select * from category where category_id between 1 and 9;
like (not like) % _
示例1:select * from category where name like 'A%';
关于NULL的条件
is NULL
is not NULL
网友评论