首页 > 数据库技术 > 详细

MYSQL简单使用

时间:2019-08-01 09:50:38      阅读:69      评论:0      收藏:0      [点我收藏+]

 

安装:

安装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:

技术分享图片

 

MYSQL简单使用

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!