Set the MySQL database sequence set to utf8

Source: Internet
Author: User
In a MySQL database, when the inserted data cannot support Chinese characters, you can set the sequence set of the database to utf8. Therefore, when creating a database, set the sequence set of the database and other characters.

In a MySQL database, when the inserted data cannot support Chinese characters, you can set the sequence set of the database to utf8. Therefore, when creating a database, set the sequence set of the database and other characters.

In a MySQL database, when the inserted data cannot support Chinese characters, you can set the sequence set of the database to utf8. Therefore, when creating a database, set the database sequence set and other character encoding to utf8.

If the dataset of the database created earlier is not utf8, you can perform the following settings:

Mysql> alter database name character set utf8;

Or delete the old database, re-create the new database, and set the default sequence set to utf8:

Mysql> create database name default character set utf8 COLLATE utf8_general_ci;

* Delete A database:

Mysql> drop database dbname if exists dbname;

* Create a database:

Mysql> create database dbname if not exists dbname;

To ensure that the database encoding set created by the create database dbname command is utf8, we can modify the mysql configuration file in windows to my. ini, my. the mysql configuration file in linux is my. cnf, mysql. cnf exists in mysql installation directory or/etc/In my. cnf or my. find [mysqld] Under ini and add a line below it:

Character_set_server = utf8

Save and exit, and restart the mysql service.

View character encoding:

Mysql> show variables like '% character % ';

Or

Mysql> show variables like 'character _ set _ % ';

Or

Mysql> use Database Name;

Mysql> \ s

Or

Mysql> use Database Name

Mysql> status;

The procedure is as follows:

Mysql> show variables like 'character _ set _ % ';
+ -------------------------- + ------------------------------------ +
| Variable_name | Value |
+ -------------------------- + ------------------------------------ +
| Character_set_client | utf8 |
| Character_set_connection | utf8 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | utf8 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/local/mysql/share/charsets/|
+ -------------------------- + ------------------------------------ +
8 rows in set (0.00 sec)


Mysql> set character_set_database = utf8;
Query OK, 0 rows affected (0.00 sec)


Mysql> set character_set_server = utf8;
Query OK, 0 rows affected (0.00 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/local/mysql/share/charsets/|
+ -------------------------- + ------------------------------------ +
8 rows in set (0.00 sec)


Mysql> use db_ets;
Database changed
Mysql> \ s
--------------
Mysql Ver 14.14 Distrib 5.7.5-m15, for linux-glibc2.5 (x86_64) using EditLine wrapper


Connection id: 16
Current database: db_ets
Current user: root @ localhost
SSL: Not in use
Current pager: stdout
Using outfile :''
Using delimiter :;
Server version: 5.7.5-m15 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket:/tmp/mysql. sock
Uptime: 23 min 45 sec


Threads: 3 Questions: 487 Slow queries: 0 Opens: 144 Flush tables: 1 Open tables: 129 Queries per second avg: 0.341
--------------


Mysql> status;
--------------
Mysql Ver 14.14 Distrib 5.7.5-m15, for linux-glibc2.5 (x86_64) using EditLine wrapper

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.