博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql5.7 windows7编码统一utf-8
阅读量:6155 次
发布时间:2019-06-21

本文共 4997 字,大约阅读时间需要 16 分钟。

mysql5.7 windows7编码统一utf-8

查看mysql数据编码

登录mysql服务,查看mysql数据库默认的编码

mysql> show variables like 'character%';+--------------------------+-------------------------------------------------+| Variable_name            | Value                                           |+--------------------------+-------------------------------------------------+| character_set_client     | gbk                                             || character_set_connection | gbk                                             || character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | gbk | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ | +--------------------------+-------------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) mysql>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

可以看出database和server都采用了latin1编码,不支持中文,我们需要把它修改为utf-8。

除了这两个,其它的如下

| 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 | E:\0Develop\mysql-5.7.15-winx64\share\charsets\
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

设置mysql数据库编码

在mysql安装目录下,将 my-default.ini 复制一分保存为 my.ini 

做如下修改 
陈科肇

主要看红色框里的内容

[mysqld]character-set-server=utf8 collation-server=utf8_general_ci [mysql]default-character-set = utf8 [mysql.server] default-character-set = utf8 [mysqld_safe] default-character-set = utf8 [client] default-character-set = utf8
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

然后删除你当前的mysql服务,再重新注册mysql服务 

注:一定要以管理员的权限运行dos命令,且cd到mysql安装目录下的bin目录,再注册mysql服务

C:\Windows\system32>sc delete mysql[SC] DeleteService 成功C:\Windows\system32>e: cd E:\>cd E:\0Develop\mysql-5.7.15-winx64\bin E:\0Develop\mysql-5.7.15-winx64\bin>mysqld --install mysql --defaults-file="E:\0Develop\mysql-5.7.15-winx64\my.ini" The service already exists! The current server installed: E:\0Develop\mysql-5.7.15-winx64\bin\mysqld MySQL E:\0Develop\mysql-5.7.15-winx64\bin>net stop mysql MySQL 服务正在停止..服务名无效。 请键入 NET HELPMSG 2185 以获得更多的帮助。 E:\0Develop\mysql-5.7.15-winx64\bin>mysqld --install mysql --defaults-file="E:\0Develop\mysql-5.7.15-winx64\my.ini" Service successfully installed. E:\0Develop\mysql-5.7.15-winx64\bin>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

结果

启动服务,查看编码

C:\Windows\System32>net start mysqlmysql 服务正在启动 .mysql 服务已经启动成功。C:\Windows\System32>mysql -u rootWelcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 2Server version: 5.7.15 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.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 | E:\0Develop\mysql-5.7.15-winx64\share\charsets\ | +--------------------------+-------------------------------------------------+ 8 rows in set, 1 warning (0.00 sec) mysql>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

数据库实例编码设置

mysql> show create database test;+----------+-----------------------------------------------------------------+| Database | Create Database                                                 |+----------+-----------------------------------------------------------------+| test     | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET latin1 */ |+----------+-----------------------------------------------------------------+1 row in set (0.00 sec)mysql> alter database test default character set utf8;Query OK, 1 row affected (0.00 sec)mysql> show create database test;+----------+---------------------------------------------------------------+| Database | Create Database | +----------+---------------------------------------------------------------+ | test | CREATE DATABASE `test` /*!40100 DEFAULT CHARACTER SET utf8 */ | +----------+---------------------------------------------------------------+ 1 row in set (0.00 sec) mysql>

二、重新启动MySql服务即可

三、查看mysql字符集 (默认情况下,mysql的字符集是latin1)

1. 启动mysql后,以root登录mysql

2. 输入命令

show variables like 'character%'; 

 
 

转载于:https://www.cnblogs.com/xc1234/p/9050522.html

你可能感兴趣的文章
C# 获取调用方信息
查看>>
成都区域赛总结
查看>>
Exception.InnerException 属性的使用
查看>>
Android 第一个OpenGL ES程序
查看>>
Android 游戏开发 View框架
查看>>
自定义菜单用例
查看>>
获取request中的查询参数
查看>>
POJ 3026 Borg Maze
查看>>
判断IP地址是否合法类
查看>>
linux 常用命令
查看>>
python 中的input
查看>>
Codeforces Round #348 (VK Cup 2016 Round 2, Div. 2 Edition) D. Little Artem and Dance 模拟
查看>>
SSL延迟有多大 (Https)
查看>>
const constexpr C++ 解释
查看>>
zookeeper leader选举机制
查看>>
Java 反射机制[Field反射]
查看>>
深入理解Delete(JavaScript)
查看>>
JS 借助 pako.js 实现网络请求获取 gzip 数据流并解析, 解决汉字乱码
查看>>
28.Node.js 函数和匿名函数
查看>>
python练习笔记——分解质因数
查看>>