这是 my-default.ini
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required
default-character-set = utf8
character_set_server = utf8
basedir = D:\Program Files\mysql
datadir = D:\Program Files\mysql\data
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysql]
default-character-set=utf8
[mysql.server]
default-character-set = utf8
[mysqld_safe]
default-character-set = utf8
[client]
default-character-set = utf8
但是在命令行中
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 | latin1 |
| character_set_system | utf8 |
| character_sets_dir | D:\Program Files\mysql\share\charsets\ |
+--------------------------+----------------------------------------+
8 rows in set
mysql>
如你所见,我确实在 my-defualt.ini 中做了很多设置,但每次 MYSQL 服务器启动时,character_set_server 总是 latin1。
我想要它是utf8,我该怎么做?
我想为什么?
谢谢!!!
最佳答案
可能您需要将my-default.ini
复制到my.ini
,因为后者是mysqld
默认查找的内容。
否则,我无法重复您的问题。
我在 Windows 8.1 上运行 5.6.12。这是测试用例,首先在 my.ini 中没有提及 character_set_server
:
mysql> show variables like 'char%';
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 | -- Note
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)
mysql> create database whatischarset;
Query OK, 1 row affected (0.03 sec)
mysql> show create database whatischarset;
+---------------+--------------------------------------------------------------------------+
| Database | Create Database |
+---------------+--------------------------------------------------------------------------+
| whatischarset | CREATE DATABASE `whatischarset` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+---------------+--------------------------------------------------------------------------+
1 row in set (0.00 sec)
此时,我将 character_set_server = utf8
添加到相应 my.ini
的 [mysqld]
部分;然后重新启动mysqld。现在...
mysql> show variables like 'char%';
+--------------------------+-----------------------------------------------+
| Variable_name | Value |
+--------------------------+-----------------------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 | -- Note
| character_set_system | utf8 |
| character_sets_dir | c:\wamp\bin\mysql\mysql5.6.12\share\charsets\ |
+--------------------------+-----------------------------------------------+
8 rows in set (0.00 sec)
mysql> create database whatischarset2;
Query OK, 1 row affected (0.00 sec)
mysql> show create database whatischarset2;
+----------------+-------------------------------------------------------------------------+
| Database | Create Database |
+----------------+-------------------------------------------------------------------------+
| whatischarset2 | CREATE DATABASE `whatischarset2` /*!40100 DEFAULT CHARACTER SET utf8 */ |
+----------------+-------------------------------------------------------------------------+
1 row in set (0.00 sec)
这与您所做的相比如何?
关于mysql - 为什么mysql服务器字符不能设置为my-default.ini(windows)中的设置(utf8)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31386542/