The default encoding settings of the MySQL server. The following uses mysql5 under MacPorts as an example to describe the setting method.
The default encoding settings of the MySQL server. The following uses mysql5 under MacPorts as an example to describe the setting method.
Re-edit encoding
First Copy my. cnf to/opt/local/etc/mysql5:
The code is as follows: |
|
$ Cd/opt/local/etc/mysql5/ $ Sudo cp/opt/local/share/mysql5/mysql/my-small.cnf my. cnf |
Edit my. cnf and add the following two lines in [mysqld:
The code is as follows: |
|
$ Sudo vi my. cnf [Mysqld] ... Collation_server = utf8_general_ci Character_set_server = utf8 After saving and exiting, restart mysqld: $ Sudo/opt/local/bin/mysqladmin5-u root shutdown $ Sudo/opt/local/bin/mysqld_safe5 & |
Modified during installation
When installing mysql source code, the simplest is:
The code is as follows: |
|
./Configure -- prefix =/usr/local/mysql |
In this case, the default encoding is latin1. However, sometimes an existing system uses gbk, gb2312, and utf8 encoding.
Modify the default value.
Normally, these encodings are not available. Therefore, you need to add these encodings to mysql during compilation and use the following command:
The code is as follows: |
|
./Configure -- prefix =/usr/local/mysql -- with-extra-charsets = gbk, gb2312, UTF-8 Then make & make install |
In the system, follow these steps to modify the default MySQL encoding:
• Stop MySQL running
The code is as follows: |
|
/Etc/init. d/mysql start (stop) is used to start and stop the server. • The MySQL main configuration file is my. cnf, and the general directory is/etc/mysql Var/lib/mysql/stores the table folder. here, mysql is equivalent to the date folder of mysql in windows. |
• When we need to modify the default encoding of the MySQL database, we need to edit the my. cnf file for encoding modification and modify the mysql configuration file in linux.
My. cnf, default file location/etc/my. cnf file
Find the client configuration [client] and add it below
The code is as follows: |
|
Default-character-set = utf8 default character set: utf8
|
Add in [mysqld]
The code is as follows: |
|
Default-character-set = utf8 default character set: utf8 Init_connect = 'set NAMES utf8' (utf8 encoding is used to SET the connection to the mysql database to run utf8) |
After modification, restart mysql.