Last active
March 14, 2018 09:11
-
-
Save spiderChow/8b353b681ededa39b5e08c013d2c4c93 to your computer and use it in GitHub Desktop.
要支持中文需要utf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1. | |
| mysql> show variables LIKE 'char%'; | |
| mysql> show variables like 'collation%'; | |
| 查看数据库默认的编码 | |
| 发现有latin1,因为mysql是瑞典人写的啊 | |
| 2.查看数据库编码 | |
| To set the default to UTF-8, you want to add the following to /etc/my.cnf | |
| [client] | |
| default-character-set=utf8 | |
| [mysql] | |
| default-character-set=utf8 | |
| [mysqld] | |
| collation-server = utf8_unicode_ci | |
| init-connect='SET NAMES utf8' | |
| character-set-server = utf8 | |
| /etc/init.d/mysql restart 重启服务器 | |
| 3. 不过呢,创建数据库和每一张表的时候也需要指定utf8编码 | |
| 创建数据库表 | |
| mysql>CREATE DATABASE my_db default charset utf8 COLLATE utf8_general_ci; | |
| 修改表的编码方式:ALTER TABLE `test` DEFAULT CHARACTER SET utf8; | |
| 该命令用于将表test的编码方式改为utf8; | |
| 修改字段的编码方式:ALTER TABLE `test` CHANGE `name` `name` VARCHAR(36) CHARACTER SET utf8 NOT NULL; | |
| 该命令用于将表test中name字段的编码方式改为utf8 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment