Modify the default encoding settings for the MySQL server

Source: Internet
Author: User

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.

Related Article

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.