安装 msi版本 添加删除数据库(DB) create database database_name;
建立database_name
数据库 show databases;
显示当前所有的数据库 drop database database_name;
删除database_name数据库 use database_name;
使用database_name
数据库 mysql的数据类型 数值类型 文本类型 时间类型 https://www.cnblogs.com/-xlp/p/8617760.html 添加和删除数据表(table) https://www.cnblogs.com/whgk/p/6158107.html
create table table_name(
id bigint ( 20 ) ,
. .
. .);
drop table table_name(
给数据表添加或者删除列’
alter table table_name add column_name; '添加表'
alter table table_name drop column_name; '删除表'
alter table table_name rename new_table_name; '重命名表'
修改某个数据列的名字或者数据类型
alter table table_name change old_table_name new_table_name data type
alter table account change city newcity varchar ( 255 ) ; '修改列的名字,但不修改数据类型'
alter table account change newcity newcity text ; '修改数据类型'
alter table account change newcity city varchat; '列的名字和数据类型同时修改;'
查看或者插入表格
select * from tabel_name; 查看所有表内容
select col_name1, col_name2, . . . . from table_name; '查看表内某几列的内容;'
insert into table_name values ( 值1 ,值2 )
insert into table_name values (列1 ,列2. . . )values (值1 ,值2. . . )
wherer 查询条件
select * form table_name
where col_name 运算符 ;
= , !, = , > , < , <= , >= , between , like '通过 and or 多个条件筛选'
ex:
select * form table_name where col1= xxx and col2 = xx or col3> xxx;
null 的判断
' 对于null的判读不能用= 或者!=来判断 需要用 is 或者is not '
select * form table_name where col_name is null ;
select distinct去掉重复查询结果
select distinct col_name from table_name; '将重复的结果筛选掉。多次只输出一次。'
使用order by对查询结果排序
'按照单一列名排序'
select * form table_name [ where 子句] order by col_name[ asc / desc ]
'where 子句不能与order by子句置换'
'按照多列排序'
select * form table_name [ where 子句] order by col_name[ asc / desc ] ,col2[ asc / desc ]
使用limit截取查询结果 只显示前三行 select * form table_name [where 子句][order by 子句]limit[offset,]rowcount
offset
表示记录从第一行 0开始 要开始截取的位置 比如 从第三行开始 offset =2, rowcount
是从 offset
开始获取截取的在那个条数 举例 limit 1,2
是从第二条开始截取两条 结果输出第二 第三行记录。 插入命令insert
和查询命令select
的组合使用 -将一个表格内的数据插入到另一个表格。-
insert into table_name values ( 值1 ,值2 )
insert into table_name values (列1 ,列2. . . )values (值1 ,值2. . . )
'组合用法'
insert into table_name1 select col1, col2 from table_name2
insert into table_name1 ( col1, col2) select col3, col4 from table_name2
更新表的数据 修改单列 updata table_name set col_name=xxx[where 字句]
修改多列 updata table_name set col_name=xxx,col2_name=xxx[where 字句]
where语句中in操作符使用
select * form tabel_name [ where col_name in ( value1, value2. . . ) ]
select * from table_name [ where col_name in ( select 筛选语句) ]
where语句中between操作符使用
select * form tabel_name [ where col_name between value1 and value2]
select * from table_name[ where col_name not between value1 and value2]
where语句中like操作符使用
select * form tabel_name [ where col_name ( not ) like pattern]
patern 匹配模式
'' abc' 完全匹配'
'' % abc' 以 abc结尾的字符串'
'' abc% ' 以abc开头的字符串'
'' % abc% ' 字符串中包含abc'
'匹配的单引号 必须有'