Skip to content

Commit 6dd36eb

Browse files
committed
[add] set charset
1 parent b85c2ee commit 6dd36eb

File tree

1 file changed

+59
-7
lines changed

1 file changed

+59
-7
lines changed

mysql.md

+59-7
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
## 常用命令
44
1. `desc;` 查看表结构
55
2. `show variables like 'char%';` 查看字符集设置
6-
3. `source file.sql;` 导入数据,要在file.sql目录下进行
7-
4. centOS下,`etc/my.cfg`,设置MySQL字符集
8-
5. `service mysqld restart` 重启MySQL
9-
6. `mysql -u root -p` 登录MySQL
10-
7. `select version();` 查看MySQL版本(要先登录MySQL)
11-
8. `status;` 查看MySQL状态(版本、字符集等)
6+
3. `show charset` 查看支持的字符集
7+
4. `source file.sql;` 导入数据,要在file.sql目录下进行
8+
5. centOS下,`etc/my.cfg`,设置MySQL字符集
9+
6. `service mysqld restart` 重启MySQL
10+
7. `mysql -u root -p` 登录MySQL
11+
8. `select version();` 查看MySQL版本(要先登录MySQL)
12+
9. `status;` 查看MySQL状态(版本、字符集等)
1213

1314
## 数据备份
1415

@@ -48,4 +49,55 @@ mysql -u root -p db < books.sql
4849
## 注意事项
4950

5051
1. MySQL在 5.5.3 之后增加了 **utf8mb4** 字符编码,mb4即 most bytes 4。简单说 utf8mb4 是 utf8 的超集并完全兼容utf8,能够用四个字节存储更多的字符。而utf8 是 utf8mb3 的别名。标准的 UTF-8 字符集编码是可以用 1~4 个字节去编码21位字符,但是MySQL其实实现的utf8只是使用3个字节而已, `utf8mb4才是真正意义上的 utf8``emoji`表情要用utf8mb4存
51-
2.
52+
53+
## MySQL5.7修改字符集
54+
55+
配置文件位置:
56+
57+
```mysql
58+
/etc/mysql/mysql.conf.d/mysqld.cnf
59+
```
60+
61+
设置为utf8mb4:
62+
63+
```mysqll
64+
# Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
65+
#
66+
# This program is free software; you can redistribute it and/or modify
67+
# it under the terms of the GNU General Public License as published by
68+
# the Free Software Foundation; version 2 of the License.
69+
#
70+
# This program is distributed in the hope that it will be useful,
71+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
72+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+
# GNU General Public License for more details.
74+
#
75+
# You should have received a copy of the GNU General Public License
76+
# along with this program; if not, write to the Free Software
77+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
78+
79+
#
80+
# The MySQL Server configuration file.
81+
#
82+
# For explanations see
83+
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
84+
#------------------------------------------------ add 1
85+
[client]
86+
default-character-set=utf8mb4
87+
#------------------------------------------------ add 2
88+
89+
[mysqld]
90+
pid-file = /var/run/mysqld/mysqld.pid
91+
socket = /var/run/mysqld/mysqld.sock
92+
datadir = /var/lib/mysql
93+
#log-error = /var/log/mysql/error.log
94+
# By default we only accept connections from localhost
95+
#bind-address = 127.0.0.1
96+
# Disabling symbolic-links is recommended to prevent assorted security risks
97+
symbolic-links=0
98+
#------------------------------------------------ add 2
99+
character-set-server=utf8mb4
100+
#------------------------------------------------ add 2
101+
```
102+
103+
上面中两处add是要加的内容,加完之后重启MySQL,然后登陆MySQL,执行`status`查看当前状态。

0 commit comments

Comments
 (0)