Modify the default character set in MySQL.

Source: Internet
Author: User

Modify the default character set in MySQL.

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

 


Mysql changes the default Character Set

Let's take a look at my picture to answer the question. I won't be able to answer the question for a hundred times when I submit the answer.




How does one set the default character set for mysql database?

Use the mysql command to modify:
Modify the character set of a Database
Mysql> use mydb
Mysql> alter database mydb character set UTF-8;
Creates a database and specifies the character set of the database.
Mysql> create database mydb character set UTF-8;

Modify the configuration file:
Modify/var/lib/mysql/mydb/db. opt
Default-character-set = latin1
Default-collation = latin1_swedish_ci
Is
Default-character-set = utf8
Default-collation = utf8_general_ci
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.