Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

View and set the MySQL database character set

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

View and set the MySQL database character set

Modify the MySQL character set under Liunx:

1. Find the location of the cnf file for MySQL

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

two。 Copy one of small.cnf, my-medium.cnf, my-huge.cnf, my-innodb-heavy-4G.cnf to / etc and name it my.cnf

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

3. Modify my.cnf

Vi / etc/my.cnf

Add under [client]

Default-character-set=utf8

Add under [mysqld]

Default-character-set=utf8

4. Restart MySQL

[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.

5. View character set settin

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 >

Some other setting methods:

Modify the character set of the database

Mysql > use mydb

Mysql > alter database mydb character set utf-8

Create the character set of the specified database

Mysql > create database mydb character set utf-8

Modify through the configuration file:

Modify / var/lib/mysql/mydb/db.opt

Default-character-set=latin1

Default-collation=latin1_swedish_ci

For

Default-character-set=utf8

Default-collation=utf8_general_ci

Restart MySQL:

[root@bogon ~] # / etc/rc.d/init.d/mysql restart

Modify through the MySQL command line:

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)

View:

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.03 sec)

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.04 sec)

[@ more@]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report