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

后端 未结 16 1029
有刺的猬
有刺的猬 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 07:04

    For Windows Users

    In addition to @davidwinterbottom answer, windows users can use command below:

    mysql.exe --database=[database] -u [user] -p[password] -B -N -e "SHOW TABLES" \
    | awk.exe '{print "SET foreign_key_checks = 0; ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci; SET foreign_key_checks = 1; "}' \
    | mysql.exe -u [user] -p[password] --database=[database] &
    

    Replace [database], [user] and [password] placeholders with actual values.

    Git-bash users can download this bash script and run it easily.

提交回复
热议问题