insert,update,references | |
+-------+-------------+-------------------+------+-----+---------+-------+---------------------------------+---------+
2 rows in set (0.01 sec)
修改列的字符集
mysql> alter table t3 change a2 a2 varchar(10) character set utf8;
Query OK, 0 rows affected (0.03 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show full columns from t3;
+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |
+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
| a1 | varchar(10) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
| a2 | varchar(10) | utf8_general_ci | YES | | NULL | | select,insert,update,references | |
+-------+-------------+-----------------+------+-----+---------+-------+---------------------------------+---------+
2 rows in set (0.00 sec)
mysql>
结论:字符集从
数据库、表、列的字符集是逐级继承的关系
查看字符集命令
mysql> show create table t4; //显示表字符集
mysql> show create database db2; //显示库字符集
mysql> show full columns from t4; //显示列字符集
alter database db2 default character set utf8; //更改库的字符集
alter table t2 convert to character set latin1;//更改表的现存列字符集
alter table t2 default character set utf8; //更能改表的默认字符集
alter table t3 change a2 a2 varchar(10) character set utf8; //更能改字段的字符集
www.2cto.com
2.修改mysql的默认存储引擎
mysql> show variables like 'storage%';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | MyISAM |
+----------------+--------+
1 row in set (0.01 sec)
mysql>
在[mysqld]下添加如下参数
default-storage-engine=innodb
重启mysql服务,查看
mysql> show variables like 'storage%';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| storage_engine | InnoDB |
+----------------+--------+
1 row in set (0.01 sec)
mysql>
创建默认字符集的表
mysql> create table t4 (a1 int);
Query OK, 0 rows affected (0.01 sec)
mysql> show create table t4;
+-------+--------------------------------------------------------------------------------------+
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------+
| t4 | CREATE TABLE `t4` (
`a1` int(11) default NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
更改表的默认字符集
mysql> alter table t4 engine myisam;
Query OK, 0 rows affected (0.06 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show create table t4;
+-------+--------------------------------------------------------------------------------------+ www.2cto.com
| Table | Create Table |
+-------+--------------------------------------------------------------------------------------+
| t4 | CREATE TABLE `t4` (
`a1` int(11) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |