MySQL modifies the default character set _ MySQL

Source: Internet
Author: User
MySQL modifies the default character set

When I was working on a program project today, I needed to modify the default character set of MySQL. Baidu tried several methods in the blog post and finally succeeded. However, I feel that the blog posts are a bit messy, so I want to help people who encounter the same problems.

Original blog: http://www.cnblogs.com/xingyunblog/p/3836299.html

Now let's get down to the truth:

There are two methods to modify the default character set of MySQL.

One is to modify the configuration of the my. ini file, and the other is to run the mysql command.

(But the first method is recommended, because the second method does not seem to work very well, because during the test, when the command is successfully modified and then opened again, the original character set is automatically restored .)

**************************************** *********************

Method 1:

1. first find your MySQL installation path. for example, my installation path is:

D:/Program Files/MySQL Server 5.1

2. open the my. ini file and modify the default character set in [mysql] and the default character set in [mysqld]. here I have changed the original latin1 to utf8.

3. after modification, save the file and restart the mysql service.

Method 2: run the mysql command.

1. press the shortcut key ctrl + r to open the running Window. enter cmd and press enter.

2. enter "d:" and press the Enter key to enter the root directory of drive d.

3. switch to the mysql installation directory and enter the following command:

cd D:/Program Files/MySQL/MySQL Server 5.1

4. log on to the database and enter the command: (note that there is no space between-u and root, and there is no space between-p and password ).

Mysql-uroot-p password

5. as shown in the following figure, the logon is successful.

6. view the current mysql default character set command:

show variables like 'character_set%';

7. enter the following commands to modify them one by one.

mysql> set character_set_client=utf8;Query OK, 0 rows affected (0.00 sec)mysql> set character_set_connection=utf8;Query OK, 0 rows affected (0.00 sec)mysql> set character_set_database=utf8;Query OK, 0 rows affected (0.00 sec)mysql> set character_set_results=utf8;Query OK, 0 rows affected (0.00 sec)mysql> set character_set_server=utf8;Query OK, 0 rows affected (0.00 sec)mysql> set character_set_system=utf8;Query OK, 0 rows affected (0.01 sec)mysql> set collation_connection=utf8;Query OK, 0 rows affected (0.01 sec)mysql> set collation_database=utf8;Query OK, 0 rows affected (0.01 sec)mysql> set collation_server=utf8;Query OK, 0 rows affected (0.01 sec)

8. view the current mysql character set command:

mysql> show variables like 'character_set_%';

**************************************** ********************************

There are two methods to restart the mysql service:

1. doscommand;

2. Graphic User Interface Operations.

**************************************** **************************************** ****************

Method 1: run the doscommand

1. press the shortcut key ctrl + r to open the running Window. enter cmd and press enter.

2. stop the mysql service command:

sc stop mysql

3. enable the mysql command:

sc start mysql 

**************************************** *************************************

Method 2: Use the user interface to operate the graph.

1. right-click my computer and choose manage from the shortcut menu;

Or press the shortcut key ctrl + r to open the running window and enter the command:

services.msc

2. find the service under "services and applications", for details:

Other blog posts on this issue: MySQL modifies the default character set

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.