Migrating MySQL UTF8 to UTF8MB4 problems and questions

前端 未结 3 1137
-上瘾入骨i
-上瘾入骨i 2021-01-02 14:03

Im trying to convert my UTF8 MySQL 5.5.30 database to UTF8MB4. I have looked at this article https://mathiasbynens.be/notes/mysql-utf8mb4 but have some questions.

I

3条回答
  •  没有蜡笔的小新
    2021-01-02 14:46

    DB="database_name"
    USER="mysql_user"
    PASS="mysql_password"
    (
        echo 'ALTER DATABASE `'"$DB"'` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
        mysql -p$PASS -u $USER "$DB" -e "SHOW TABLES" --batch --skip-column-names \
        | xargs -I{} echo 'ALTER TABLE `'{}'` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;'
    ) \
    | mysql -p$PASS -u $USER "$DB"
    
    • To get the script you work open your command line and use the following steps:

      1. nano convert_to_utf8mb4.sh
      2. paste the script & save
      3. sudo chmod 755 convert_to_utf8mb4.sh (in terminal)
      4. run the script by type ./convert_to_utf8mb4.sh

      Yes, collation has been changed!

提交回复
热议问题