A script to change all tables and fields to the utf-8-bin collation in MYSQL

后端 未结 16 1013
有刺的猬
有刺的猬 2020-12-04 06:24

Is there a SQL or PHP script that I can run that will change the default collation in all tables and fields in a database?

I can write one

16条回答
  •  萌比男神i
    2020-12-04 06:49

    I think it's easy to do this in two steps runin PhpMyAdmin.
    Step 1:

    SELECT CONCAT('ALTER TABLE `', t.`TABLE_SCHEMA`, '`.`', t.`TABLE_NAME`,
     '` CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;') as stmt 
    FROM `information_schema`.`TABLES` t
    WHERE 1
    AND t.`TABLE_SCHEMA` = 'database_name'
    ORDER BY 1
    

    Step 2:
    This query will output a list of queries, one for each table. You have to copy the list of queries, and paste them to the command line or to PhpMyAdmin's SQL tab for the changes to be made.

提交回复
热议问题