Modify the default encoding settings of the MySQL server-mysql tutorial

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.