Today in the study of MySQL found my code is: latin1 situation, should not support Chinese, although has not tried, let him modify it.
Check the default situation first:
Mysql> Show variables like '%collation% '; Query commands from the Internet, although I don't know what this collation is for.
+--------------------------+----------------------------+
| variable_name | Value |
+---------------------------+----------------------------+
| collation_connection | Latin1_swedish_ci |
| Collation_database | Latin1_swedish_ci |
| Collation_server | Latin1_swedish_ci |
+--------------------------+------------------------------+
3 rows in Set (0.01 sec)
Then carried out again:
mysql> SHOW VARIABLES like '%character% '; This should be the meaning of the character format.
+---------------------------------+------------------------------------------------+
| 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/local/mysql/share/mysql/charsets/|
+--------------------------+----------------------------------------+
8 rows in Set (0.00 sec)
Basically the above are all Latin, to be modified:
Locate the MY.CNF configuration file for editing:
--Add the following to the [Mysqld] tab:
Default-character-set = UTF8
Character_set_server = UTF8
Save Exit!
Restart the MySQL service, my restart method is more stupid, kill the process!
[Email protected]:/usr/local/mysql/bin#PS aux | grep "MySQL"
Root 3945 0.0 0.0 4476 1664? S 13:52 0:00/bin/sh./mysqld_safe--user=root
Root 4062 0.0 0.4 423308 33792? Sl 13:52 0:03/usr/local/mysql/libexec/mysqld--basedir=/usr/local/mysql--datadir=/usr/local/mysql/var--user=root- -log-error=/usr/local/mysql/var/b-thinkpad-x230s.err--pid-file=/usr/local/mysql/var/b-thinkpad-x230s.pid-- Socket=/tmp/mysql.sock--port=3306
Root 13262 0.0 0.0 13712 2144 pts/18 s+ 16:11 0:00 grep--color=auto MySQL
[Email protected]:/usr/local/mysql/bin#kill-9 3945
[Email protected]:/usr/local/mysql/bin#kill-9 4062
Kill it and run it again:
[Email protected]:/usr/local/mysql/bin# ./mysqld_safe--user=root
151218 16:12:23 mysqld_safe Logging to '/usr/local/mysql/var/b-thinkpad-x230s.err '.
151218 16:12:23 Mysqld_safe starting mysqld daemon with databases From/usr/local/mysql/var
Then execute the above query command:
Mysql> Show variables like '%character% ';
+-----------------------------------+----------------------------------------+
| variable_name | Value |
+----------------------------------+--------------------------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | Latin1 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/local/mysql/share/mysql/charsets/|
+------------------------------------+----------------------------------------------+
8 rows in Set (0.01 sec)
The changes have been found:
Character_set_database
Character_set_server
A few have not changed, then change:
Character_set_client;character_set_connection;character_set_results
Follow the online tutorials:
Note: If something like "DEFAULT-CHARACTER-SET=GBK" already exists under this tab, just modify it.
--Add a line under the [MySQL] tab
Default-character-set = UTF8
--Add a line under the [Mysql.server] tab
Default-character-set = UTF8
--Add a line under the [Mysqld_safe] tab
Default-character-set = UTF8
--Add a line under the [Client] tab
Default-character-set = UTF8
My my.cnf does not have so many areas, such as: [Mysqld_safe][mysql.server] These I later manually add!
Add complete, then reboot, log in, check:
The results are unsatisfactory!
mysql> SHOW VARIABLES like '%character% ';
+--------------------------+----------------------------------------+
| variable_name | Value |
+--------------------------+----------------------------------------+
| character_set_client | Latin1 |
| character_set_connection | Latin1 |
| Character_set_database | UTF8 |
| Character_set_filesystem | binary |
| Character_set_results | Latin1 |
| Character_set_server | UTF8 |
| Character_set_system | UTF8 |
| Character_sets_dir | /usr/local/mysql/share/mysql/charsets/|
+--------------------------+----------------------------------------+
8 rows in Set (0.00 sec)
Simply remove the operation just now!
On the problem of database encoding in MySQL