Linux setup MySQL database encoding UTF8

Source: Internet
Author: User
Tags wrapper

Reprint Address

Http://www.linuxidc.com/Linux/2015-08/121676.htm

In the MySQL database, when the inserted data cannot support Chinese, the encoding set of the database can be set to UTF8, so the database encoding set and other character encodings are set to UTF8 when the database is created.

If the database encoding set for the previously created database is not UTF8, you can set the following:

mysql> ALTER DATABASE name character set UTF8;

or delete the old database, 1117.www.qixoo.qixoo.com and then re-create the new database and set the default encoding set to UTF8:

Mysql> CREATE database name DEFAULT CHARACTER SET UTF8 COLLATE utf8_general_ci;

* Delete database:

Mysql> DROP Database dbname if exists dbname;

* CREATE DATABASE:

Mysql> CREATE DATABASE dbname if not exists dbname;

To make sure that the database encoding set created by the Create DB dbname command is UTF8, we can modify the MySQL configuration file to my.ini the MySQL configuration file under Windows. My.ini exists in the MySQL installation directory under linux MySQL configuration file for my.cnf, MYSQL.CNF exists in the installation directory of MySQL or/etc/under my.cnf or My.ini to find [mysqld], add a line below it:

Character_set_server=utf8

Then save the exit and restart the MySQL service.

To view character encodings:

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;

Here's how:

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 | qkxue.net/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:
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 Sockets:/tmp/mysql.sock
uptime:23 min 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


Connection id:16
Current Database:db_ets
Current User:
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 Sockets:/tmp/mysql.sock
uptime:24 min sec


Threads:5 questions:501 Slow queries:0 opens:144 Flush tables:1 Open tables:129 queries per second avg:0.344
--------------


Mysql>

MySQL modifies the default character set to Utf-8

Linux setup MySQL database encoding UTF8

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.