Change MySQL default character set to UTF8 under Mac

Source: Internet
Author: User
Tags chmod

1. First check the default installed character set

Mysql> Show variables like '%char% '; +--------------------------+----------------------------------------------- ---------+| 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-5.6.23-osx10.8-x86_64/share/charsets/|+--------------------------+--------------------------------------------------------+8 rows in Set (0.00 sec) 

Character_set_database and Character_set_server are still latin1 character sets, which means that the tables created by MySQL are all latin1 character sets, not utf8, causing some trouble. So it is necessary to modify the MY.CNF, before modifying my.cnf must close the MySQL process, otherwise you will encounter the MySQL sock can not connect problems.


2. See if there are my.cnf files in the/etc/directory

ls-al/etc/

check, found that the machine is not my.cnf, see a lot of information, they say you can go to/usr/local/mysql installation directory to find support-files, copy the following format like MY-**.CNF file into the/etc/directory. The command is as follows:

cp/usr/local/mysql/support-files/my-default.cnf/etc/


3, modify the/etc/my-default.cnf file name is my.cnf, and modify the configuration inside

Cat/etc/my.cnf

View the contents of a configuration file

Ls-l/etc/my.cnf

View file read and Write permissions, if 644 (rw-r--r--) change to (664) (rw-rw-r--)

If you change to (666) (rw-rw-rw-), the configuration file will not take effect. The following details explain why it will not take effect.

sudo chmod 664/etc/my.cnf

You can enter your password.


4. Modify the contents of the configuration file

Vi/etc/my.cnf

At the top of the file, add

[Client]default-character-set=utf8

increase under [mysqld]

Character-set-server=utf8

Type: wq! Save and exit


5. Re-view the encoding set

Mysql> Show variables like '%char% '; +--------------------------+----------------------------------------------- ---------+| 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-5.6.23-osx10.8-x86_64/share/charsets/|+--------------------------+--------------------------------------------------------+8 rows in Set (0.00 sec) 


An explanation of the problem occurred:

The first command I entered was

<span style= "color: #ff0000;" >chmod a+w/etc/my.cnf</span>
This command means that MY.CNF has permission to write to all users, so it becomes 666. Causes me to change after also does not have the error, also does not take effect.

There was an error in the database until I closed the database service and entered the database.

<span style= "color: #ff0000;" >world-writable config file '/etc/my.cnf ' is ignored</span>

It probably means that the permissions are globally writable and can be written by any user. MySQL is concerned that this file has been maliciously modified by other users, so ignore this configuration file.

Suddenly I understand, open the database service, modified to 664, and then restart the database, and then see the encoding has been successfully modified.

Change MySQL default character set to UTF8 under Mac

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.