Mysql在debian系统中不能插入中文的终极解决方案_MySQL
Jun 01, 2016 pm 01:25 PMdebian
bitsCN.com在debian环境下,彻底解决mysql无法插入和显示中文的问题
Linux下Mysql插入中文显示乱码解决方案
mysql -uroot -p 回车输入密码
进入mysql查看状态如下:
默认的是客户端和服务器都用了latin1,所以会乱码。
解决方案:
mysql>user mydb;
mysql>alter database mydb character set utf8;!
上文提到了用临时方法更改数据库的字符集设置,显示中文,但是后来发现在有的系统下并不能成功。
比如我用的debian 7.0,找了好久终于找到一个适合debian系统的解决方案,debian 7.0下测试成功,其他诸如修改client和mysql加入default-character-set=utf8的方法之类的,只适用与5.5以前的系统!
终极决绝方案,一劳永逸:
debian下mysql的字符串修改为utf8(参考:rainysia的专栏)
一、进入mysql(mysql -uroot -p),查看当前数据库字符集(status;)
二、查看当前系统版本(lsb_release -a)
三、#vim /etc/mysql/my.cnf 。(5.5以前系统)在【client】下面加入 default-character-set=utf8
在【mysqld】下面加入default-character-set=utf8
Notice:注意 如果修改后不能启动报错试试把default-character-set=utf8改为character_set_server=utf8,仅仅加入到mysqld下面的.client就不需要加了
四、#vim /etc/mysql/my.cnf 。(5.5以后系统)如下修改:
[client]
default-character-set=utf8
[mysqld]
default-storage-engine=INNODB
character-set-server=utf8
collation-server=utf8_general_ci
五、重启mysql(/etc/init.d/mysql stop /etc/init.d/mysql start)
六、修成成功,进入mysql查看字符集(mysql>show variables like ‘character_set_%';)
Mysql无法插入中文

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Solution for Win11 unable to install Chinese language pack

An effective solution to solve the problem of garbled characters caused by Oracle character set modification

Best Practice Guide for Building IP Proxy Servers with PHP

Oracle NVL function common problems and solutions

How to configure Dnsmasq as a DHCP relay server

Implementing Machine Learning Algorithms in C++: Common Challenges and Solutions

Common causes and solutions for Chinese garbled characters in MySQL installation

What should I do if I can't enter the game when the epic server is offline? Solution to why Epic cannot enter the game offline
