Download the mysql yum source from the website at the following address:
Http://repo.mysql.com/
Check the system version number on linux and download it based on the version number.
More/etc/redhat-release
Rpm-Uvh http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
Yum-y upgrade mysql
Mysql_upgrade
Modify the character set of database, table, and column
# For each database:
Alter database vipmonk character set = utf8mb4 COLLATE = utf8mb4_unicode_ci;
# For each table:
Alter table table_name convert to character set utf8mb4 COLLATE utf8mb4_unicode_ci;
# For each column:
Alter table table_name CHANGE column_name VARCHAR (191) character set utf8mb4 COLLATE utf8mb4_unicode_ci;
# (Don't blindly copy-paste this! The exact statement depends on the column type, maximum length, and other properties. The above line is just an example for a 'varchar 'column .)
Modify my. ini (my. cnf in linux)
[Client]
Default-character-set = utf8mb4
[Mysql]
Default-character-set = utf8mb4
[Mysqld]
Character-set-client-handshake = FALSE
Character-set-server = utf8mb4
Collation-server = utf8mb4_unicode_ci
Init_connect = 'set NAMES utf8mb4'
Restart Mysql and check the character set:
Mysql> show variables where Variable_name LIKE 'character \ _ set \ _ % 'OR Variable_name LIKE 'colation % ';
+ -------------------------- + -------------------- +
| Variable_name | Value |
+ -------------------------- + -------------------- +
| Character_set_client | utf8mb4 |
| Character_set_connection | utf8mb4 |
| Character_set_database | utf8mb4 |
| Character_set_filesystem | binary |
| Character_set_results | utf8mb4 |
| Character_set_server | utf8mb4 |
| Character_set_system | utf8 |
| Collation_connection | utf8mb4_unicode_ci |
| Collation_database | utf8mb4_unicode_ci |
| Collation_server | utf8mb4_unicode_ci |
+ -------------------------- + -------------------- +
10 rows in set (0.00 sec)
Modify character sets for all tables and fields
Alter table tbl_name convert to character set character_name [COLLATE...] example:
Alter table logtest convert to character set utf8 COLLATE utf8_general_ci;
// Modify character sets of all tables and fields in batches
SELECT
CONCAT ('alter table', table_name, 'convert to character set utf8mb4 COLLATE utf8mb4_unicode_ci ;')
FROM
INFORMATION_SCHEMA.tables
WHERE
TABLE_SCHEMA = 'database _ name'