【Mysql】character-set-server參數

對於數據庫級的字符集,若是沒有辦法重建數據庫,能夠在my.cnf文件中使用character-set-server = utf8(要重啓數據庫服務),對於以前已經存在數據庫,此參數不產生影響。若是以前的數據庫A是latin1,在A中建立的表默認仍是latin1,除非指定DEFAULT CHARSET!然而對於新建的數據庫,則繼承 my.cnf文件中使用character-set-server = utf8! [root@rac3 ~]# more /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql old_passwords=1 character-set-server = utf8 關閉數據庫服務,並從新啓動! [root@rac3 ~]# mysqladmin shutdown [root@rac3 ~]# mysqld_safe & [1] 15102 [root@rac3 ~]# Starting mysqld daemon with databases from /var/lib/mysql [root@rac3 ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.45 Source distribution Type '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) --從新創建數據庫,查看其默認字符集:爲utf8 mysql> 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: yql Create Database: CREATE DATABASE `yql` /*!40100 DEFAULT CHARACTER SET utf8 */ 1 row in set (0.00 sec) ERROR: No query specified
相關文章
相關標籤/搜索