当前位置:Gxlcms > PHP教程 > Linux下进行MYSQL编程时插入中文乱码的解决方案_php技巧

Linux下进行MYSQL编程时插入中文乱码的解决方案_php技巧

时间:2021-07-01 10:21:17 帮助过:28人阅读

插入中文是乱码,尝试了许多方法,比如我先把vim里设置为:set fileencoding=utf-8不起作用,后来想想也对,和vim没什么关系
然后就尝试c#代码,用Encoding.UTF8.GetString()方法,后来也不对。
我就郁闷了,忽然想起来莫不是mysql的设置问题???
于是,sudo nano /etc/mysql/my.cnf
插入下面红色代码,default-character-set = utf8,成功,不乱码了~~~根本不用什么Encoding.....
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
default-character-set = utf8
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
language = /usr/share/mysql/english
skip-external-locking

人气教程排行