If you set the default character encoding in mysql to UTF-8 and have used Linux, you will know that installing mysql in Linux, especially when using yum for installation, we cannot select the default character encoding method. This is a headache. If you use Chinese characters in a Linux database, Garbled text may cause a headache. Let's talk about Linu today.
If you set the default character encoding in mysql to UTF-8 and have used Linux, you will know that installing mysql in Linux, especially when using yum for installation, we cannot select the default character encoding method. This is a headache. If you use Chinese characters in a Linux database, Garbled text may cause a headache. Let's talk about Linu today.
Set the default character encoding in mysql to UTF-8
If you have used Linux, you will know that you cannot select the default character encoding method when installing mysql in Linux, especially when using yum. This is a headache. If you use Chinese characters in a Linux database, Garbled text may cause a headache. Today, let's talk about how to set the default encoding method in Linux.
1. First, stop the mysql service. You must have the root permission.
service mysqld stop
2. Find my under/etc. cnf file, if not, find the my-medium.cnf file under the support-files folder under the mysql installation directory, copy to/etc/and rename it my. cnf
3. Edit the my. cnf file, add default-character-set = utf8 to its [client] and [mysqld], and save and close the file.
[client]#password= your_passwordport= 3306socket= /tmp/mysql.sockdefault-character-set=utf8# Here follows entries for some specific programs# The MySQL server[mysqld]port= 3306socket= /tmp/mysql.sockskip-external-lockingkey_buffer_size = 16Mmax_allowed_packet = 1Mtable_open_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mdefault-character-set=utf8
4. Restart the service.
PS: the setting method is similar in Windows.
Find my. INI file, modify [client] and [mysqld] followed by default-character-set = utf8, if not found, find the my-medium.ini file, copy and rename it my. ini.