我在我的Ubuntu 14.04上安装了MySQL 5.7.8。
但我无法修改MySQL默认字符集。我想将字符集更改为utf8。
我在互联网上搜索并查看了很多文章,但我尝试的每种方法都不适用于我。
我已经在/etc/mysql/my.cnf中添加了'character-set-server = utf8'和'collation-server = utf8_general_ci'。但它不起作用......
如何更改MySQL的字符集?请回答我!
MySQL中的状态
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /var/run/mysqld/mysqld.sock
Uptime: 1 min 24 sec
显示'c%'
等变量| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
| check_proxy_users | OFF |
| collation_connection | utf8_general_ci |
| collation_database | latin1_swedish_ci |
| collation_server | latin1_swedish_ci |
| completion_type | NO_CHAIN |
| concurrent_insert | AUTO |
| connect_timeout | 10 |
| core_file | OFF |
my.cnf(在/ etc / mysql中)
[mysqld]
#
# * Basic Settings
#
character-set-server=utf8
collation-server=utf8_general_ci
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
character-set-server=utf8
collation-server=utf8_general_ci
init_connect=set collation_connection=utf8_general_ci
init_connect=set names utf8
character-set-client-handshake=FALSE
答案 0 :(得分:10)
character set
和collation
: sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
然后按 i 并添加以下内容:
...
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
...
按 Esc 然后: w 然后: q !
然后重启服务器:
sudo /etc/init.d/mysql restart
检查您的配置:
mysql> show variables like "%character%";
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.01 sec)
mysql> show variables like "%collation%";
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
character set
和collation
:创建数据库时明确指定:
CREATE DATABASE some_database CHARACTER SET utf8 COLLATE utf8_general_ci;
检查您的配置:
mysql> SHOW CREATE DATABASE ...
mysql> SHOW CREATE TABLE ...