Mysql插入中文数据乱码,网上说修改my.cof,可我的电脑里没有这个文件(/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf 都没有)
我先停用mysql,再新建my.cof文件输入类似:
character_set_server=utf8
init_connect='SET NAMES utf8'
或者stackoverflow上其它的都试了,再启动mysql还是显示:
mysql> show variables like '%character%';
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
直接创建文件是不是不行?请问有默认模板吗?另外我是apt-get安装的mysql
崩溃中。。。请大神指点,感激不尽
环境:
ubuntu14.04
mysql5.5.41
In 14.04, using sudo apt-get install mysql-server, the file /etc/mysql/my.cnf exists.
/usr/bin/mysql --help|grep -B 1 /etc/mysql/my.cnf
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
The later ones have higher priority. It is recommended to keep only one configuration file /etc/mysql/my.cnf.
Content:
apt-get download mysql-common download this package, there is this file in it.
Add under [mysqld] in the configuration:
character_set_server=utf8
In addition, please note that the encoding is also specified when creating databases and tables:
Also specify the encoding when connecting to the database, such as PHP:
Page output also specifies UTF-8 encoding:
The editor and IDE also use UTF-8 encoding, which will prevent garbled characters after unification.
Is this setting correct?
Look for /usr/share/mysql/my.cnf. If not, use the find command to find it:
Or check the process information to see which configuration file is loaded
mysql can be started according to a configuration file by adding --defaults-file='path/to/my.cnf' to the startup command