one:
Operating environmentubuntu:14.04
mysql:5.5.47
Enter mysql and run SHOW VARIABLES LIKE 'character_set_%'; check the supported encoding format of mysql
+--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | latin | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | latin | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
Modify all formats to utf8, modify my.cnf (and possibly my.ini)
sudo find / -name my.cnf //View path /etc/mysql/my.cnf sudo gedit /etc/mysql/my.cnf //open a file
Insert default-character-set=utf8 below [client][mysql][mysqld_safe]
Insert character-set-server=utf8 under [mysqld]
then click save
restart mysql
sudo /etc/init.d/mysql restart
Check again and enter mysql to view the encoding format
mysql > 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/ | +--------------------------+----------------------------+ 8 rows in set (0.00 sec)
That's it
two
If the first method is not sexual, then try this one!
1. Modify the encoding format of the database
//View database code: mysql> SHOW CREATE DATABASE db_name;
+-----------+--------------------------------------------------------------------+ | Database | Create Database | +-----------+--------------------------------------------------------------------+ | GoodsInfo | CREATE DATABASE `GoodsInfo` /*!40100 DEFAULT CHARACTER SET utf8 */ | +-----------+--------------------------------------------------------------------+ 1 row in set (0.00 sec)
If it is not utf8 then delete the database and do it again
When building a database, we can set the character set of the database through the following command:
CREATE DATABASE `database` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
2. Modify the encoding format of the table
- View table encoding:
- mysql> SHOW CREATE TABLE tbl_name;
If an error is reported:
ERROR 1046 (3D000): No database selected
Execute the following:
mysql> use db_name; mysql> show create table tbl_name;
Modify the encoding method of the table: ALTER TABLE `test` DEFAULT CHARACTER SET utf8; this command is used to change the encoding method of the table test to utf8;