Re-edit the encoding
First copy a my.cnf to/OPT/LOCAL/ETC/MYSQL5:
The code is as follows |
Copy Code |
$ cd/opt/local/etc/mysql5/ $ sudo cp/opt/local/share/mysql5/mysql/my-small.cnf my.cnf |
Then edit my.cnf and add the following two lines in the [mysqld] section:
The code is as follows |
Copy Code |
$ sudo vi my.cnf [Mysqld] ... Collation_server = Utf8_general_ci Character_set_server = UTF8 Restart mysqld after saving exit: $ sudo/opt/local/bin/mysqladmin5-u Root shutdown $ sudo/opt/local/bin/mysqld_safe5 & |
Modify at Installation
MySQL source installation, the simplest is:
The code is as follows |
Copy Code |
./configure--prefix=/usr/local/mysql |
But in this case, the default encoding is latin1, but sometimes one of our existing systems uses GBK, gb2312, UTF8, and so on, which requires
Modify this default value.
These encodings are not normally available, so you need to add them to MySQL at compile time, using the following command
The code is as follows |
Copy Code |
./configure--prefix=/usr/local/mysql--with-extra-charsets=gbk,gb2312,utf-8 and then Make&&make install |
Linux System, the steps to modify the MySQL database default encoding are:
• Stop MySQL from running
The code is as follows |
Copy Code |
/etc/init.d/mysql Start (stop) starts and stops the server MySQL main configuration file is my.cnf, General directory is/etc/mysql Var/lib/mysql/is placed in the database table folder, where MySQL corresponds to the date folder under Windows MySQL |
• When we need to modify the default encoding of the MySQL database, we need to edit the my.cnf file for coding and modify the MySQL configuration file under Linux.
MY.CNF, file location default/etc/my.cnf file
Locate the client configuration [clients] add below
The code is as follows |
Copy Code |
Default-character-set=utf8 default character set is UTF8
|
After finding [mysqld] Add
The code is as follows |
Copy Code |
Default-character-set=utf8 default character set is UTF8 init_connect= ' Set NAMES UTF8 ' (set to connect to MySQL database with UTF8 encoding to make MySQL database run UTF8) |
After you've modified it, restart MySQL.