標籤:
分類: Linux
對於資料庫級的字元集,如果沒有辦法重建資料庫,可以在my.cnf檔案中使用character-set-server = utf8(要重啟資料庫服務),對於之前已經存在資料庫,此參數不產生影響。如果之前的資料庫A是latin1,在A中建立的表預設還是latin1,除非指定DEFAULT CHARSET!然而對於建立的資料庫,則繼承 my.cnf檔案中使用character-set-server = utf8! [[email protected] ~]# more /etc/my.cnf [mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysqlold_passwords=1character-set-server = utf8 關閉資料庫服務,並重新啟動![[email protected] ~]# mysqladmin shutdown[[email protected] ~]# mysqld_safe &[1] 15102[[email protected] ~]# Starting mysqld daemon with databases from /var/lib/mysql[[email protected] ~]# mysqlWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 1Server version: 5.0.45 Source distributionType ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the buffer.mysql> show variables like ‘%server%‘;+----------------------+-----------------+| Variable_name | Value |+----------------------+-----------------+| character_set_server | utf8 | | collation_server | utf8_general_ci | | server_id | 0 | +----------------------+-----------------+3 rows in set (0.00 sec)--重建立立資料庫,查看其預設字元集:為utf8mysql> create database yql;Query OK, 1 row affected (0.00 sec)mysql> use yql;Database changed建立表的預設字元集和資料庫的預設字元集一致!mysql> create table t(id int);Query OK, 0 rows affected (0.00 sec)mysql> show create table t;+-------+-------------------------------------------------------------------------------------+| Table | Create Table |+-------+-------------------------------------------------------------------------------------+| t | CREATE TABLE `t` ( `id` int(11) default NULL) ENGINE=MyISAM DEFAULT CHARSET=utf8 | +-------+-------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql> show create database yql \G; *************************** 1. row *************************** Database: yqlCreate Database: CREATE DATABASE `yql` /*!40100 DEFAULT CHARACTER SET utf8 */1 row in set (0.00 sec)ERROR: No query specified
【Mysql】character-set-server參數