安装:
安装phpstudy,通过phpstdy来学习MySQL。

然后登陆mysql,使用你的密码登陆(默认是root)
之后就可以开始学习mysql语句了。
使用:
mysql语句不区分大小写,每一个命令都是以;结束(如create database sqlname;)
\h获取帮助
\c退出编辑(如图)

进入‘>模式时,使用‘c退出到->(如图)

增加:CREATE DATABASE ’数据表名字‘;(如create database sqlname;)
创建内容:
create table teacher(
id int(4) not null primary key auto_increment,
name char(20) not null,
sex char(10) not null,
addr char(10) not null
);
插入数据:insert into teacher(name,sex,addr) values(‘Y‘,‘male‘,‘jxpx‘);
展示数据:select * from teacher;(*表示所有,这个select关键字本来是查找某个数据)
之后就是这个样子:

切换到一个数据库:use ’数据表名字‘;(如use test)
显示所有数据库:show databases;
如图:

在数据库中显示数据表:show tables;

更新数据: update teacher set name=‘Josely‘ where id=5;

更新前:
更新后:
删除数据: delete from teacher where id=5;
删除前:参考前面的图,删除后:

where句子:
select 你要的信息 from 一个表或者多个表 where 满足的条件(判断)
如:select * from teacher where sex=‘male‘;

如:select name from teacher where sex=‘male‘;

order by 语句:
select 你要的信息 from 一个表或者多个表 order by 字段 asc/desc
asc与desc表示正序与逆序(默认为asc,可以不写)
如 select * from teacher order by name;

select * from teacher order by name desc

此时,注意,order by 后面可以加数字(在sqli中有用的)
select * from teacher order by 1;(1=id)
select * from teacher order by 2;(2=name)
select * from teacher order by 3;(3=sex)
select * from teacher order by 4;(4=addr)
union语句:
select 需要的信息 from 数据表1 union select 需要的信息 from 数据表2
如图两个表:

使用select name from student union select name from teacher;后,

值得注意的是,这样子写,不会显示重复的(name为Y的两个数据只显示一个)
要显示两个,应使用union all。
select name from student union all select name from teacher;
效果如下图

使用union,还可以这样子玩:

注释:
使用#字符,或-- (减号减号空格)来注释单行,还有一个/* */。


内置函数:
database():

load_file(‘写文件路径’):

(不知道为啥没有。。。。)
current_user:

原文:https://www.cnblogs.com/This-is-Y/p/11252206.html