软件测试_MYSQL

# MYSQL
## 基础知识点
### 进入数据库:在偏好设置中打开 — 打开终端 /usr/local/mysql/bin/mysql -u root -p
### 可以把完整的命令分成几行打,完后用分号作结束标志就行
### 使用光标上下键调出以前的命令
## 常用命令
### 建立数据库:mysql>create database 库名;
删除数据库:mysql>drop database 库名; 显示数据库:mysql>show databases;
显示food 库中的表:mysql>use food mysql>show tables;
* 建立数据表:mysql>use 库名
mysql>create table 表名(字段名 varchar(20),字段名 char(1)); 删除数据表:mysql>drop table 表名;
展示表: describe 表名;
* 操作数据
* 增:insert into student values(‘123’,‘qqqq’,‘80’),(‘124’,‘yyyy’,‘90’);
* 改;update student set name=‘qqq1111’ where stuid=‘123’;
* 查
* 模糊查询:select * from student where name like ‘q%’;
* 排序查询:selec * from student order by grade;
* 复杂查询: 17.左连接查询:
select * from students left join information on students.s_id=information.d_id;
19.全连接查询(mySql不支持全连接,所以用左连接union右连接)
select 表1.*,表2.* from 表1 left (outer) join 表2 on 表1.字段=表2.字段 union select表1.*,表2.* from 表1 right (outer) join 表2 on 表1.字段=表2.字段;
例:select s.*,p.* from student s left join people p on s.name = p.name union select s.*,p.* from student s right join people p on s.name = p.name;
* 对字段的操作的 alter
* 增加表的一个字段alter table student add column sex char(10) (default 1);
添加新主键:alter table student add primary key(stuid);
* 删除表的一个字段:alter table student drop column name; 删除表主键:alter table student drop primary key;
* .修改字段属性:alter table student change name newname char(20) null;
修改表设置默认字段:alter table student modify name char(10) defalt 7;

*XMind: ZEN - Trial Version*

原文地址:https://www.cnblogs.com/yaozhi/p/10270942.html