mysql基础回忆帮助:
1.启动
以管理员身份启动命令行或shell
在命令行中输入net start mysql启动MySQL服务(退出输入net stop mysql)
2.连接mysql
启动mysql服务后输入mysql -uroot -ppasswd连接mysql
3.基本运用
<1>mysql存储结构: 数据库 -> 表 -> 数据 sql语句
<2>管理数据库:
? 增加: create database 数据库名 default character utf8;
? 删除: drop database 数据库名;
? 修改: alter database 数据库名 default character gbk;
? 查询: show databases / show create database 数据库名;
<3>管理表:
? 选择数据库:use 数据库;
? 增加: create table 表(字段名1 字段类型,字段名2 字段类型......);
? 删除: drop table 表;
? 修改:
? 添加字段: alter table 表 add [column] 字段名 字段类型;
? 删除字段: alter table 表 drop [column] 字段名;
? 修改字段类型: alter table 表 modify 字段名 新的字段类型;
? 修改字段名称 : alter table 表 change 旧字段名 新字段名 字段类型;
? 修改表名称: alter table 表 rename [to] 新表名;
? 查询:
? show tables(查表名)
? desc 表名=show columns from 表名;
<4>管理数据:
? 增加: insert into 表(字段1,字段2,。。。) values(值1,值2.。。。。);
? 删除: delete from 表 where 条件;
? 修改: update 表 set 字段1=值1,字段2=值2...... where 条件;
? 查询:
? 4.1)所有字段: select * from 表;
? 4.2)指定字段: select 字段1,字段2.... from 表;
? 4.3)指定别名: select 字段1 as 别名 from 表;
? 4.4 )合并列: select (字段1+字段2) from 表;
? 4.5)去重: select distinct 字段 from 表;
? 4.6)条件查询:
? a)逻辑条件 :and(与) or(或)
? select * from 表 where 条件1 and/or 条件2
? b)比较条件: > < >= <= = <> between A and B
? select * from 表 where servlet>=90;
? c)判空条件:
? 判断null: is null / is not null
? 判断空字符串: =‘‘ / <>‘‘
? d)模糊条件: like
? %: 替换任意个字符
? _: 替换一个字符
? 4.7 分页查询:limit 起始行,查询行数
? 起始行从0开始
? 4.8 排序: order by 字段 asc/desc
? asc: 正序,顺序
? desc:反序,倒序
? 4.9 分组查询:group by 字段
? 4.10: 分组后筛选: having 条件
? 4.11:多表查询: select 表1.字段1,表1.字段2,表2.字段1,表2.字段2 from 表1,表2
? where 表1.字段x=a and(or) 表2.字段y=b;
?
? SQL语句的分类:
? DDL: 数据定义语言
? create / drop / alter
? DML:数据操作语句
? insert / delete /update
? DQL: 数据查询语言:
? select / show
原文:https://www.cnblogs.com/rookieshome/p/14801946.html