sql基础一
一:mysql的安装
1、进入解压安装包,创建my.ini文件
2、以管理员身份打开cmd
cd C:\web\mysql-\bin
初始化数据库
mysqld --initialize --console
安装mysql
mysqld install
启动mysql
net start mysql
3、登录mysql
mysql -h 主机名 -u 用户名 -p
-h:指定客户端所要登录的mysql主机名
-u:登陆的用户名
-p:告诉服务器将会用一个密码来登录
4、修改初始化密码
alter user'root'@"localhost"identified by "111111"
二:sql语法
1、创建数据库
greate database 数据库名;
2、删除数据库
drop database 数据库名;
3、选择数据库
user 数据库名;
4、查询数据库中的列表
show 数据库名;
5、删除数据表
drop table 表名;
6、查找数据
select * from table;
7、查找并去除重复数值
select distinct * from table;
8、查找满足条件的数据
select * from table where value=value;
between and 在什么之间
in 指定针对某个列表的多种可能
9、搜索某种模式
select * from table like "%m_";
10、多表查询
select * from table_1 (left/right)join table_2 on value=value;
11、查找排序
select * from table order by id asc/desc;
12、插入语句
insert into table value ();
13、更新语句
update table set value=value where id=1;
14、删除数据表中数据
delete from table where id=1;
15、主键的设置与作用
主键的设置:primarykey
作用:唯一标识
16、连接两个以上的查询组合到一个语句中
select * from table_1 union select * from table_2;
17、分组查询
select name,count(*) from table group by name;
sum()
with rollup在分组的基础上进行相同的统计

浙公网安备 33010602011771号