Modify the default encoding in MySQL Linux.

Source: Internet
Author: User

Modify the default encoding in MySQL Linux.

The younger brother recorded the modification of the default MySQL encoding here, and changed the default encoding to utf8. I hope this article will help you. Thank you!

Environment:

Linux: centeros 6.6 (as shown below) and Ubuntu 12.04 (see red font at the end of the article)

MySQL version: 5.1.73

First, go to the MySQL command line interface. You can refer to my article: simple operations in MySQL Linux.

Check the default MySQL encoding,

Enter the command: show variables like '% character % ';

Example:


Next, exit MySQL and enter the command: exit; or use another terminal to switch to the Administrator status.

Here there are several ways to modify, younger brother know two, one is here this elder brother's method, address: http://www.2cto.com/database/201204/127849.html

The younger brother's system originally had the/etc/my. cnf file mentioned above, so it was not replaced. Instead, it was directly modified in the/etc/my. cnf file. In fact, the principle is the same here. The replace and modification method of this brother is to set the MySQL startup parameters, and the younger brother's method is to simply set parameters using the existing files.

Then go to the MySQL configuration file/etc/my. cnf to modify it,

Run vim/etc/my. cnf.

Example:


Add the following code to the yellow mark

Default-character-set = utf8

Init_connect = 'set NAMES utf8'

[Client]

Default-character-set = utf8

Explanation:

The first two sentences are to modify the default encoding for the server, and the last two sentences are to set the default encoding for the client.

Init_connect = 'set NAMES utf8' (utf8 encoding is used to SET the connection to the mysql database to run utf8). This line of code can be added or not added.

After completion, it is as follows:


Then restart the MySQL service and enter MySQL.

Enter the following command:

Service mysqld restart

Mysql-uroot-p123456 (123456 is the password, or you can remove it to hide the password input)

Run the following command to check whether the default encoding has changed:

Enter the command: show variables like '% character % ';

The Modification result is as follows:


 

Note: All of the above are modified in the center OS system. The configuration file modified in the Ubuntu system is not/etc/my. cnf, but/etc/mysql/my. cnf. The modification process is shown in the figure above. The modified File


Restart the MySQL service, go to MySQL, and check the encoding to find that the encoding has changed.

Reprinted please indicate the source: http://blog.csdn.net/yannanying/Article/details/43087049

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.