mysql数据库基本操作
前言:上一次我们已经将mysql安装好了,这一次我们来学习下mysql的基本操作毕竟是人就会犯错,我这写博客都是写实风格的,以前有的实验犯大错那肯定是写不下辽,但是有时过程中犯点小错,直接就改过来,改错过程也都在实验中写出来了,知错能改,善莫大焉,望大家引以为戒
先登录mysql
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/160142176.png)
查看当前数据库
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/160329445.png)
创建一个学校数据库
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/160518548.png)
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/160552723.png)
进入school数据库
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/161711844.png)
显示里面数据
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/161809819.png)
我们来建立一个有学号,姓名,地址和成绩的表
学号名称为4长度,不允许为空
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/162449792.png)
姓名为10长度,不允许为空
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/162600653.png)
地址为50长度可变,默认地址为南京
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/162810970.png)
成绩为精确数值
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/163126847.png)
定义主线
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/163252480.png)
。。。。enmm,所谓人有失足,马有失蹄,俺刚刚不小心打错了。导致错误,不过大家也别担心,小错误。error报错之后,大家按下方向键↑,把我们刚刚打的这段话当中的第一句create改下,我少加了一个e,这就是考验大家英语好不好的小插曲~
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/163652600.png)
查看表结构
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/164129965.png)
接下来我们来编辑下表
插入数值,values后面的数值要跟前面的对应好
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/165016034.png)
下面再继续添加,方法一样的
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/165528915.png)
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/165646159.png)
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/165953440.png)
查询下
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170015376.png)
如果想修改表格呢,俺们该这样
修改表格的地址信息为杭州,目标是id为4,名字为stu04(哈哈,这种白话文翻译对着我的输入字符看就行了)
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170435711.png)
查看
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170509245.png)
修改成功
能修改那就能删除,那下面看看怎么删除
我们删除stu04
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170709852.png)
查看,发现stu04没了
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170728068.png)
如果你想把整个表删除
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170905424.png)
你会发现表么得了,你也用不了查看表信息了
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/170937074.png)
那show tables会显示为空
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/171023951.png)
it界神话,删库跑路
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/171136277.png)
这下连school也么得了
你再看看
![mark](http://itmc.oss-cn-hangzhou.aliyuncs.com/blog/20200202/171217969.png)
现在啥都么得了,好了万法归一,收功~