码迷,mamicode.com
首页 > 数据库 > 详细

数据库mysql的基本操作

时间:2020-04-07 22:31:46      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:文件夹   开头   复制   表结构   HERE   lte   tween   charset   base   

操作文件夹(数据库)

1 增:create database db1 charset utf8;
2 查:show databases;
3 改:alter database db1 charset latin1;
4 删除: drop database db1
5 
6 查看当前所在的数据库
7 select database();

操作文件(表)

1 先切换到文件夹下:use db1
2      增:create table t1(id int,name char);
3      查:show tables
4      改:alter table t1 modify name char(3);
5          alter table t1 change name name1 char(2);
6      删:drop table t1;
7 
8     查看表结构
9     describe t1;

修改表结构

https://book.apeland.cn/details/460/

表的内容操作

1,增

1 insert into [表名] values(1,wu),(2,zhi),(3,bin);
2 insert into [] (列名,列名....) values (值,值,值....),(值,值,值....);
3 insert into [表1] (列名,列名...) select 列名,列名... from 表2; #将表1复制给表二
1 delete from []   #清空表
2 delete from [] where id =1 and name=wu;   #按条件删除
1 update [] set name = wang where id =1;   #按条件修改
1 select * from []  #显示表中所有的列和数据
2 select * from [] where id >1 ; #按条件查询
其他
#对条件查询
slect * from [] where id > 5 and name != wuzhibin;
slect * from [] where id between 4 and 9;
select * from [] where id in (1,3,5);
select * from [表1] where id in (select id from  [表2]) # 条件是表2中的ID
1 #通配符查询
2 select * from [] where name like wu% ; #以wu开头后面可以匹配多个字符
3 select * from [] where name like wu_ ; # 以wu开头后面最多匹配一个字符
1 #查询限制
2 select * from [] limit 5 ; #前面5行数据
3 select * from [] limit 4,5; #从第五行开始的5行
4 select * from [] limit 5 offset 4  # 从第武汉开始的5行
1 #排序查询
2 select * from [] order by [] asc;  #从小到大
3 select * from [] order by [] desc;  #从大到小
4 select * from [] order by [列1] asc[列2] desc ; 列1相等在根据列2排序
1 #两张表组合查询
2 select name from [表1]  union select name from [表2];  #自动去重
3 select name from [表1] union all select name from [表2]; #不去重
1 #连表操作
2  select t1.id ,t1.name ,t2.name from t1,t2 where t1.nid = t2.id; 

 

数据库mysql的基本操作

标签:文件夹   开头   复制   表结构   HERE   lte   tween   charset   base   

原文地址:https://www.cnblogs.com/wuzhibinsuib/p/12656270.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!