How to modify the default encoding in MySQL Linux
The younger brother recorded the modification of the default MySQL encoding here, and changed the default encoding to utf8. I hope this article will help you. Thank you!
Environment:
Linux: centeros 6.6 (as shown below) and Ubuntu 12.04 (see red font at the end of the article)
MySQL version: 5.1.73
First, go to the MySQL command line interface. You can refer to my article: simple operations in MySQL Linux.
Check the default MySQL encoding,
Enter the command: show variables like '% character % ';
Example:
Next, exit MySQL and enter the command: exit; or use another terminal to switch to the Administrator status.
Here there are several ways to modify, younger brother know two, one is here this elder brother's method, address: http://www.bkjia.com/database/201204/127849.html
The younger brother's system originally had the/etc/my. cnf file mentioned above, so it was not replaced. Instead, it was directly modified in the/etc/my. cnf file. In fact, the principle is the same here. The replace and modification method of this brother is to set the MySQL startup parameters, and the younger brother's method is to simply set parameters using the existing files.
Then go to the MySQL configuration file/etc/my. cnf to modify it,
Run vim/etc/my. cnf.
Example:
Add the following code to the yellow mark
Default-character-set = utf8
Init_connect = 'set NAMES utf8'
[Client]
Default-character-set = utf8
Explanation:
The first two sentences are to modify the default encoding for the server, and the last two sentences are to set the default encoding for the client.
Init_connect = 'set NAMES utf8' (utf8 encoding is used to SET the connection to the mysql database to run utf8). This line of code can be added or not added.
After completion, it is as follows:
Then restart the MySQL service and enter MySQL.
Enter the following command:
Service mysqld restart
Mysql-uroot-p123456 (123456 is the password, or you can remove it to hide the password input)
Run the following command to check whether the default encoding has changed:
Enter the command: show variables like '% character % ';
The Modification result is as follows:
Note: All of the above are modified in the center OS system. The configuration file modified in the Ubuntu system is not/etc/my. cnf, but/etc/mysql/my. cnf. The modification process is shown in the figure above. The modified File
Restart the MySQL service, go to MySQL, and check the encoding to find that the encoding has changed.