1. 连接数据库
#net start mysql服务器启动
#net stop mysql服务器停止
#mysql -h 192.168.6.127 -u root -p 1234 登入账户
2.数据库
#2.1 创建数据库
#create database test;
#show create database test;
#2.2 使用数据库
#use test;
#2.3 修改数据库;
#alter database test CHARACTER set gbk;
#2.4 删除库
#drop database test;
3. 表
3.1 创建表
#注意:字段类型需记住
3.2 修改表
3.2.1 alter table tablename add column_name type; ----增加列
3.2.2 alter table tablename change column_name new_type; —修改列类型
3.2.3 alter table tablename change old_column_name new_column_name type; ----修改列名
3.2.4 alter table tablename drop column_name; —删除列
3.2.5 alter table tablename rename to new_tablename —重命名表名
3.3 删除表 #drop table tablename
4. 数据
4.1 增 #insert into tablename(列)(值);
4.2 改 #update tablename set column_name = values where pan’bie #update mysql_exam.t_role set id=‘1004’ where id=‘1003’;
4.3 删 #delete from mysql_exam.t_role where id=‘1004’ TRUNCATE TABLE tablename;
4.4 查
#select * 列名,列名 distinct 字段 from 表名 where 条件 ;
#select * form 表; 查询所有记录
#select * from product; 查询所有列
#查询某张表特定列
#select 列名 from 表;
#去重查询
#SELECT DISTINCT 字段名 FROM 表名;
#别名查询
#select 列名 as 别名 ,列名 from 表; 列别名查询
#select 别名.* from 表 as 别名; 表别名查询
#运算查询(+,-,*,/等
#select pname , price+10 from product;运算查询
#条件查询
#SELECT xx FROM 表名 WHERE 条件; //取出表中的每条数据,满足条件的记录就返回,不满足条件的记录不返回
#between 小的值 and 大的值 , 闭区间 ;
#eg: price between 3000 and 6000 —> 3000<= price <= 6000 2. 字段 like ‘模糊的值’; like通常和占位符一起使用 _ 占一位, % 占多位(0~n) uname like ‘张%’ ----> 张 张三 张三三 uname like ‘张_’ ----> 张三