Mysql database encoding settings under Ubuntu

Mysql database utf8 encoding settings under Ubuntu ,


When operating the mysql database, it is necessary to access Chinese characters, but it cannot be stored in the presence of /4x/7x/xx

What's the most annoying thing

But I have a point when I change the code. I don't know the reason. When I change it to gbk, there are garbled characters.

what? , Isn't gbk the solution to Chinese characters? Why is it still garbled?

It's ok, it's just a problem in my personal computer, if your computer can use gbk then use it,

However, it is recommended to change to utf8, the problem will be relatively less.


Then let's solve it.


The first step :

Enter sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf to enter this file

Find lc-messages-dir= /usr/share/mysql this one

Add a sentence below: character-set-server=utf8


Step 2:

Enter sudo gedit /etc/mysql/conf.d/mysql.cnf to enter this file

After entering, under [mysql]

Add a statement: default-character-set=utf8


Step 3: Restart the MySQL service

/etc/init.d/mysql restart


Step 4: Enter the database to view the results

Enter the database:

mysql -u root -p

After entering, enter:

show variables like 'char%';

Check the encoding (don't miss the " ; " symbol in the statement)

However, the encoding of one of the character_set_filesystem is still: binary, it doesn't matter

He doesn't affect anything, at least it doesn't seem to me a big problem, so don't waste time modifying him.


Finally, it is worth noting that if you still have encoding problems when storing Chinese character data, then you need to

Check the encoding of the database you created





Enter: show create database database name;

get:

name    | CREATE DATABASE `sunck` /*!40100 DEFAULT CHARACTER SET binary */

是不是没有改成utf8?,那就修改编码吧,


alter database 数据库名 character set utf8 ;

然就再查看,问题就解决了,记得,以后创建数据库,记得指定编码创建吧


创建数据库并指定编码:create database 数据库名 character set utf8 ;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325585579&siteId=291194637