以下的文章主要向大家講述的是MySQL數據庫中的字符集設定的所有參數為UTF8的實際操作過程,我們大家都知道在安裝完成之後已經對MySQL數據庫設置為utf8,但是有時會出現以下的內容,如:
- MySQL(和PHP搭配之最佳組合)> SHOW VARIABLES LIKE 'collation_%';
- +----------------------+-------------------+
- | Variable_name | Value |
- +----------------------+-------------------+
- | collation_connection | latin1_swedish_ci |
- | collation_database | utf8_general_ci |
- | collation_server | utf8_general_ci |
- +----------------------+-------------------+
- 3 rows in set (0.00 sec)
MySQL(和PHP搭配之最佳組合)> SHOW VARIABLES LIKE 'character_set_%';
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | latin1 |
- | character_set_connection | latin1 |
- | character_set_database | utf8 |
- | character_set_results | latin1 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳組合)\MySQL(和PHP搭配之最佳組合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
發覺畫線標注的屬性還是非 utf8的。
然後修改 my.ini 文件,設置
以下是代碼片段:
- [client]
- default-character-set=utf8
- [MySQL(和PHP搭配之最佳組合)]
- default-character-set=utf8
- [MySQL(和PHP搭配之最佳組合)d]
- default-character-set=utf8
copy my.ini 文件到 windows目錄
啟動MySQL數據庫 以下是代碼片段:
- MySQL(和PHP搭配之最佳組合)> SHOW VARIABLES LIKE ’character_set_%’;
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_results | utf8 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳組合)\MySQL(和PHP搭配之最佳組合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
- MySQL(和PHP搭配之最佳組合)> SHOW VARIABLES LIKE ’character_set_%’;
- +--------------------------+------------------------------------------------+
- | Variable_name | Value |
- +--------------------------+------------------------------------------------+
- | character_set_client | utf8 |
- | character_set_connection | utf8 |
- | character_set_database | utf8 |
- | character_set_results | utf8 |
- | character_set_server | utf8 |
- | character_set_system | utf8 |
- | character_sets_dir | D:\data\MySQL(和PHP搭配之最佳組合)\MySQL(和PHP搭配之最佳組合) Server 4.1\share\charsets/ |
- +--------------------------+------------------------------------------------+
- 7 rows in set (0.00 sec)
一切正常了。
創建數據庫:
以下是代碼片段:
- create table t_sysuser (
- USERID integer not null auto_increment,
- USERNAME varchar(30),
- PASSWORDS varchar(30),
- DEPTNO varchar(30),
- HEADSHIP varchar(30),
- SEX varchar(4),
- TEL varchar(18),
- EMAIL varchar(30),
- URL varchar(30),
- PCALL varchar(20),
- USERPHOTO varchar(255),
- FACEREFUTIME integer,
- FACELANGUAGE varchar(1),
- LASTMODIF varchar(30),
- LASTMDATE datetime,
- CREADTOR varchar(30),
- CREATDATE datetime,
- Prima(最完善的虛擬主機管理系統)ry key (USERID)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
全部搞定。
以上的相關內容就是對MySQL數據庫的字符集設定所有參數為UTF8的介紹,望你能有所收獲。