MySQL bulk modifies the character set of the database

Source: Internet
Author: User

#走过, the way I tried

UPDATE information_schema. ' schemata ' SET  default_collation_name= ' utf8_general_ci '  WHERE default_collation _name<> ' Utf8_general_ci ';

# ———— Try to use the UPDATE statement to modify, this is not working, the following error does not have permissions.

#错误代码: 1044
#Access denied for user ' root ' @ '% ' to database ' Information_schema '

# after the Niang find the data, you need to use the ALTER statement to modify the DB character set

ALTER DATABASE mydb CHARACTER SET UTF8;

#第一步, find the database in the MySQL instance where the character set is not UTF8

SELECT *  from WHERE Default_collation_name<>'utf8_general_ci';

#第二步, modifying the character set

#如果MySQL实例上有多个数据库需要将字符集改为utf8, we can take the following strategy:

#2.1 using the Concat function, I believe you can see the following statement, you should be able to know what to do next.

SELECT *, CONCAT (', schema_name,'  CHARACTER SET UTF8; '  from WHERE Default_collation_name<>'utf8_general_ci';

#2.2 Copy the result of the previous select, paste, and finally execute

ALTER DATABASE CHARACTER SET UTF8; ALTER DATABASE CHARACTER SET UTF8; ALTER DATABASE CHARACTER SET UTF8, .......

#第三步, check that validation is successful

SELECT *  from WHERE Default_collation_name<>'utf8_general_ci';

#<r> query: SELECT * from INFORMATION_SCHEMA. ' schemata ' WHERE default_collation_name<> ' utf8_general_ci ' LIMIT 0, 1000
#返回了 0 Rows

#结果表明, there is no character set that's not UTF8 's library anymore.

Done!

MySQL bulk modifies the character set of the database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.