Linux use service mysql restart command to restart MySQL service
The new database will use this character set as the default character set
Modify the character set of each database in the MySQL server
If there is a database before setting the server character set. You need to change the character set of the database:
The code is as follows |
Copy Code |
Use Datatable_name; ALTER DATABASE character set GBK; |
Other questions about changing character sets
Character set modified later found that the use of stored procedures to do new operations, but also appear in Chinese garbled, but directly write SQL statements will not appear garbled.
View Character Set settings
The code is as follows |
Copy Code |
Mysql> Show variables like ' collation_% '; +----------------------+-----------------+ | variable_name | Value | +----------------------+-----------------+ | collation_connection | Utf8_general_ci | | Collation_database | Utf8_general_ci | | Collation_server | Utf8_general_ci | +----------------------+-----------------+ 3 Rows in Set (0.02 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/share/mysql/charsets/| +--------------------------+----------------------------+ 8 rows in Set (0.02 sec) Mysql> |
1. Find the location of the MySQL cnf file
The code is as follows |
Copy Code |
Find/-iname ' *.cnf '-print /usr/share/mysql/my-innodb-heavy-4g.cnf /usr/share/mysql/my-large.cnf /usr/share/mysql/my-small.cnf /usr/share/mysql/my-medium.cnf /usr/share/mysql/my-huge.cnf /usr/share/texmf/web2c/texmf.cnf /usr/share/texmf/web2c/mktex.cnf /usr/share/texmf/web2c/fmtutil.cnf /usr/share/texmf/tex/xmltex/xmltexfmtutil.cnf /usr/share/texmf/tex/jadetex/jadefmtutil.cnf /usr/share/doc/mysql-server-community-5.1.22/my-innodb-heavy-4g.cnf /usr/share/doc/mysql-server-community-5.1.22/my-large.cnf /usr/share/doc/mysql-server-community-5.1.22/my-small.cnf /usr/share/doc/mysql-server-community-5.1.22/my-medium.cnf /usr/share/doc/mysql-server-community-5.1.22/my-huge.cnf |
2. Copy
The code is as follows |
Copy Code |
SMALL.CNF, MY-MEDIUM.CNF, MY-HUGE.CNF, my-innodb-heavy-4g.cnf one of them to/etc, named My.cnf Cp/usr/share/mysql/my-medium.cnf/etc/my.cnf |
3. Modify MY.CNF
The code is as follows |
Copy Code |
Vi/etc/my.cnf Add under [client] Default-character-set=utf8 Add under [mysqld] Default-character-set=utf8 |
4. Restart MySQL
The code is as follows |
Copy Code |
[Root@bogon ~]#/etc/rc.d/init.d/mysql restart shutting down mysql [OK] Starting mysql. [OK] [Root@bogon ~]# mysql-u root-p Enter password: > Welcome to the MySQL Monitor. Commands End With; or G. Your MySQL connection ID is 1 Server version:5.1.22-rc-community-log MySQL Community Edition (GPL) Type ' Help, ' or ' h ' for help. Type ' C ' to clear the buffer. |