标签:mysql
第二章
涉及到database的所有语句里,schema关键字和database同义
1. 查询当前回话,和全局回话的sql_mode
Select @@session.sql_mode;
select @@global.sql_mode;
set sql_mode = ‘TRADITIONAL‘
set GLOBAL sql_mode = ‘TRADITIONAL‘
2.4.字符集支持
查询当前server支持那些字符集,和排序规则
show charset; # show character set; select * from information_schema.CHARACTER_SETS;
查看服务器的设置
show collation; #select * from information_schema.COLLATIONS;
show variables; 查看当前终端的变量
show global variables; 查看服务器全局变量
2.5.数据库操作
创建
create database if not exists test1 character set utf8 collate utf8_general_ci;
查看建库语句
show create database test1;
删除
drop database test1;
修改数据库
alter database test1 [character set utf8] [collate utf8_general_ci];
2.6 数据表操作
创建表语句,可设置默认字符,和排序规则
create table if not exists tbl_name (...) character set 字符编码 collate 排序规则 engines = innodb;
临时表,当前回话退回后,表会自动删除,如果创建的表明,和当前库中表同名,会暂时隐藏原有的表.
create temporary table tbl_name ..
删除表
drop table tbl_name;
修改表
alter table tbl_name ...
新建索引
create index ..
删除索引
drop index...
查看建表语句
show create table tbl_name;
查看表的基本信息
desc tbl_name;
2.6.24 根据其他表或查询结果创建表
复制一个表结构,包括索引和各列的属性,只能完整复制单个表,不能选择列等.
create [TEMPORARY] table tbl_name1 like tbl_name;
从查询插入数据,
insert into tbl_name1 select * from tbl_name.
直接将查询结果保存到一个新表,可以同时查询多个表的多个列,生成一个新的表,
create table tbl_name1 select id from tbl_name;
create table t3 select t1.c t2.c as c2 from t1 inner join t2;
显式定义部分列,需要在查询中提供显式定义的列.
create table tbl_name (i not unsigned , t time,d decimal(10,5))
select
1 as i,
cast(curtime() as time) as t,
cast (pi() as decimal(10,5) as d;
强制类型转换
CAST(val as type) ,转换值为某个类型
允许强制转换的类型,binary, char, date, datetime, time, signed, signed integer, unsigned, unsigned integer, decimal
查看当前server支持那些存储引擎
show engines; # select * from information_schema.engines;
标签:mysql
原文地址:http://quxf2012.blog.51cto.com/12149748/1883381