目前我们在 PHP 中使用以下命令将字符集设置为 UTF-8 在我们的应用程序中.
Currently we are using the following commands in PHP to set the character set to UTF-8 in our application.
由于这有点开销,我们希望将其设置为 MySQL 中的默认设置.我们可以在/etc/my.cnf 或其他位置执行此操作吗?
Since this is a bit of overhead, we'd like to set this as the default setting in MySQL. Can we do this in /etc/my.cnf or in another location?
SET NAMES 'utf8'
SET CHARACTER SET utf8
我在/etc/my.cnf 中寻找了默认字符集,但没有关于字符集的内容.
I've looked for a default charset in /etc/my.cnf, but there's nothing there about charsets.
此时,我执行以下操作将 MySQL 字符集和排序规则变量设置为 UTF-8:
At this point, I did the following to set the MySQL charset and collation variables to UTF-8:
skip-character-set-client-handshake
character_set_client=utf8
character_set_server=utf8
这是处理这个问题的正确方法吗?
Is that a correct way to handle this?
要设置默认为UTF-8,需要在my.cnf/my.ini中添加以下内容
To set the default to UTF-8, you want to add the following to my.cnf/my.ini
[client]
default-character-set=utf8mb4
[mysql]
default-character-set=utf8mb4
[mysqld]
collation-server = utf8mb4_unicode_520_ci
init-connect='SET NAMES utf8mb4'
character-set-server = utf8mb4
如果您想更改现有数据库的字符集,请告诉我...您的问题没有直接指定它,所以我不确定这是否是您想要做的.
If you want to change the character set for an existing DB, let me know... your question didn't specify it directly so I am not sure if that's what you want to do.
由于 utf8 只是 UTF-8 的一个子集,我在原始答案中用 utf8mb4 替换了 utf8.MySQL 和 MariaDB 都调用 UTF-8 utf8mb4.
I replaced utf8 with utf8mb4 in the original answer due to utf8 only being a subset of UTF-8. MySQL and MariaDB both call UTF-8 utf8mb4.
这篇关于在 my.cnf 中将 MySQL 默认字符集更改为 UTF-8?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何有效地使用窗口函数根据 N 个先前值来决定How to use windowing functions efficiently to decide next N number of rows based on N number of previous values(如何有效地使用窗口函数根据
在“GROUP BY"中重用选择表达式的结果;条款reuse the result of a select expression in the quot;GROUP BYquot; clause?(在“GROUP BY中重用选择表达式的结果;条款?)
Pyspark DataFrameWriter jdbc 函数的 ignore 选项是忽略整Does ignore option of Pyspark DataFrameWriter jdbc function ignore entire transaction or just offending rows?(Pyspark DataFrameWriter jdbc 函数的 ig
使用 INSERT INTO table ON DUPLICATE KEY 时出错,使用 Error while using INSERT INTO table ON DUPLICATE KEY, using a for loop array(使用 INSERT INTO table ON DUPLICATE KEY 时出错,使用 for 循环数组
pyspark mysql jdbc load 调用 o23.load 时发生错误 没有合pyspark mysql jdbc load An error occurred while calling o23.load No suitable driver(pyspark mysql jdbc load 调用 o23.load 时发生错误 没有合适的
如何将 Apache Spark 与 MySQL 集成以将数据库表作为How to integrate Apache Spark with MySQL for reading database tables as a spark dataframe?(如何将 Apache Spark 与 MySQL 集成以将数据库表作为