Modify the default MySQL database encoding in Ubuntu

Source: Internet
Author: User
MySQL configuration file location:/etc/mysql/my. cnf. database Table Folder:/var/lib/mysql/. log on to MySQL in the date folder of MySQL under Windows in UbuntuLinux and execute the code: showvariableslike 'character % '; + ------------------------ + ---------------------

MySQL
Main configuration file location:/etc/mysql/my. cnf.

Database Table Folder:/var/lib/mysql/, which is equivalent to the date folder of MySQL in Windows in Ubuntu Linux

Log on to MySQL and run the encoding:

Show variables like 'character % ';

+ -------------------------- + ---------------------------- +
| Variable_name | Value |
+ -------------------------- + ---------------------------- +
| Character_set_client | latin1 |
| Character_set_connection | latin1 |
| Character_set_database | latin1 |
| Character_set_filesystem | binary |
| Character_set_results | latin1 |
| Character_set_server | latin1 |
| Character_set_system | utf8 |
| Character_sets_dir |/usr/share/mysql/charsets/|
+ -------------------------- + ---------------------------- +


Modify the encoding of the default MySQL database

You need to edit the my. cnf file. For Windows, you can directly use Mysql Server Instance Config Wizard to set

Sudo gedit/etc/mysql/my. cnf

Find [client] and add:

Default-character-set = utf8 // The default character set is utf8

Find [mysqld] and add:

// The default character set is utf8.
Default-character-set = utf8
// Set utf8 encoding when connecting to the mysql database to run the mysql database as utf8
Init_connect = 'set NAMES utf8'


After modification, restart mysql.

Query show variables like 'character % ';

+ -------------------------- + ---------------------------- +
| 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/|
+ -------------------------- + ---------------------------- +

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.