Liunx How to modify the MySQL character set

Source: Internet
Author: User
Tags character set

Linux use service mysql restart command to restart MySQL service

The new database will use this character set as the default character set

Modify the character set of each database in the MySQL server

If there is a database before setting the server character set. You need to change the character set of the database:

The code is as follows Copy Code

Use Datatable_name;
ALTER DATABASE character set GBK;

Other questions about changing character sets

Character set modified later found that the use of stored procedures to do new operations, but also appear in Chinese garbled, but directly write SQL statements will not appear garbled.

View Character Set settings

The code is as follows Copy Code
Mysql> Show variables like ' collation_% ';
+----------------------+-----------------+
| variable_name | Value |
+----------------------+-----------------+
| collation_connection | Utf8_general_ci |
| Collation_database | Utf8_general_ci |
| Collation_server | Utf8_general_ci |
+----------------------+-----------------+
3 Rows in Set (0.02 sec)
Mysql> Show variables like ' character_set_% ';
+--------------------------+----------------------------+
| variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | UTF8 |
| character_set_connection | UTF8 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | UTF8 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/share/mysql/charsets/|
+--------------------------+----------------------------+
8 rows in Set (0.02 sec)
Mysql>

1. Find the location of the MySQL cnf file

The code is as follows Copy Code

Find/-iname ' *.cnf '-print

/usr/share/mysql/my-innodb-heavy-4g.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-small.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/texmf/web2c/texmf.cnf
/usr/share/texmf/web2c/mktex.cnf
/usr/share/texmf/web2c/fmtutil.cnf
/usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf
/usr/share/texmf/tex/jadetex/jadefmtutil.cnf
/usr/share/doc/mysql-server-community-5.1.22/my-innodb-heavy-4g.cnf
/usr/share/doc/mysql-server-community-5.1.22/my-large.cnf
/usr/share/doc/mysql-server-community-5.1.22/my-small.cnf
/usr/share/doc/mysql-server-community-5.1.22/my-medium.cnf
/usr/share/doc/mysql-server-community-5.1.22/my-huge.cnf

2. Copy

The code is as follows Copy Code

SMALL.CNF, MY-MEDIUM.CNF, MY-HUGE.CNF, my-innodb-heavy-4g.cnf one of them to/etc, named My.cnf

Cp/usr/share/mysql/my-medium.cnf/etc/my.cnf

3. Modify MY.CNF

The code is as follows Copy Code

Vi/etc/my.cnf
Add under [client]
Default-character-set=utf8
Add under [mysqld]
Default-character-set=utf8

4. Restart MySQL

The code is as follows Copy Code

[Root@bogon ~]#/etc/rc.d/init.d/mysql restart
shutting down mysql                                           [OK]
Starting mysql.                                               [OK]
[Root@bogon ~]# mysql-u root-p
Enter password:
> Welcome to the MySQL Monitor. Commands End With; or G.
Your MySQL connection ID is 1
Server version:5.1.22-rc-community-log MySQL Community Edition (GPL)
Type ' Help, ' or ' h ' for help. Type ' C ' to clear the buffer.

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.