来源:自学PHP网 时间:2015-04-16 10:50 作者: 阅读:次
[导读] mysql编码设置MYSQL 2009-09-11 15:37 阅读73 评论1 字号: 大大 中中 小小mysql SHOW VARIABLES LIKE character_set_% ; 43;-------------------------- 43;--------------------------...
mysql编码设置 MYSQL 2009-09-11 15:37 阅读73 评论1 字号: 大大 中中 小小 mysql> SHOW VARIABLES LIKE 'character_set_%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 7 rows in set (0.00 sec) mysql> SHOW VARIABLES LIKE 'collation_%'; +----------------------+-------------------+ | Variable_name | Value | +----------------------+-------------------+ | collation_connection | latin1_swedish_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | +----------------------+-------------------+ 3 rows in set (0.00 sec) 默认就是瑞典latin1,一下是换成我们自己的编码,如utf8: 1. SET NAMES 'utf8'; 它相当于下面的三句指令: SET character_set_client = utf8; SET character_set_results = utf8; SET character_set_connection = utf8; 一般只有在访问之前执行这个代码就解决问题了,下面是创建数据库和数据表的,设置为我们自己的编码格式。 3. 创建表 CREATE TABLE `type` ( `id` int(10) unsigned NOT NULL auto_increment, `flag_deleted` enum('Y','N') character set utf8 NOT NULL default 'N', `flag_type` int(5) NOT NULL default '0', `type_name` varchar(50) character set utf8 NOT NULL default '', PRIMARY KEY (`id`) ) DEFAULT CHARSET=utf8; 4. 修改数据库成utf8的. 5. 修改表默认用utf8. 6. 修改字段用utf8 =================================================================== 最近开始使用MySql,以前都是用Oracle,嫌太贵了,呵呵 设置步骤: 一、编辑MySql的配置文件 --在 [mysqld] 标签下加上三行 default-character-set = utf8 character_set_server = utf8 lower_case_table_names = 1 //表名不区分大小写(此与编码无关) --在 [mysql] 标签下加上一行 default-character-set = utf8 --在 [mysql.server]标签下加上一行 default-character-set = utf8 --在 [mysqld_safe]标签下加上一行 default-character-set = utf8 --在 [client]标签下加上一行 default-character-set = utf8 二、重新启动MySql服务 Linux下面可是用 service mysql restart 如果出现启动失败,请检查配置文件有没有设置错误 三、查看设置结果 | 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 | /usr/share/mysql/charsets/ | 如果仍有编码不是utf8的,请检查配置文件,也可使用mysql命令设置: set character_set_client = utf8; set character_set_server = utf8; set character_set_connection = utf8; set character_set_database = utf8; set character_set_results = utf8; set collation_connection = utf8_general_ci; set collation_database = utf8_general_ci; set collation_server = utf8_general_ci;
四、建库导入数据 五、程序连接字符串(此项与mysql设置无关,为程序开发使用) 六、附录
|
自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习
京ICP备14009008号-1@版权所有www.zixuephp.com
网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com