mysql 连接命令 表管理 ,克隆表,临时表,字符串属性,设定语句间的分隔符

连接和断开
连接
mysql -h host -u user -p (即,连接的主机、用户名和使用的密码)。
断开
输入QUIT (或q)随时退出:


表管理
克隆表
注意:create table ... like 语句不克隆表的外键定义,不克隆原表可能使用的data directory 和index directory. 和auto_increment


--创建一张和现有的某张表结构一致的表。
create table new_table like original_table

 

--把某张的数据插入到克隆好的表插入
insert into new_table select * from original_table
insert into new_table(列) select 列 from original_table


--克隆一表,把数据也复制过来。
create table new_table select * from original_table

 

临时表
临时表是与各个数据库连接相关的,断开连接自动删除临时表。
临时表具有的另外一个特性是,临时表可以使用普通表的表名,这样做的结果是,在临时表的生命周期内,它将屏蔽与之同名的普通表。

创建临时表
create temporary table 新表名 like 目录表名
删除临时表
drop temporary table 表名。(temporary关键字在这里,可以避免错误的删除同名的普通表。)

drop table 表名。


改变表的存储引擎
MyISAM
alter table 表名 engine = InnoDB

查看表的存储引擎
select engine from information_schema.`TABLES` where TABLE_NAME='表名'


字符串属性
分为两类,二进制和非二进制。
非二进制字符串的特征之一:是它们有一个字符集。
查看系统字符集 show character set;
非二进制字符串的特征之二:Collation
查看字符集中的Collation 用: show COLLATION;
也可以只查看特定字符集的Collation例如:show COLLATION like 'latin1%';

 

delimiter // 设定语句间的分隔符为//

select * from `user`;
select * from `user`
改成
delimiter //
select * from `user`//
select * from `user`

原文地址:https://www.cnblogs.com/longhs/p/4338210.html