欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL8 批量修改字符集腳本

 更新時(shí)間:2023年03月24日 10:44:47   作者:wzy0623  
本文主要介紹了MySQL8 批量修改字符集腳本,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧

從低版本遷移到MySQL 8后,可能由于字符集問(wèn)題出現(xiàn) Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) 錯(cuò)誤,此時(shí)要修改對(duì)象的字符集。

1. 批量修改庫(kù)字符集

change_database_characset.sql

select concat('alter database ',schema_name,' default character set utf8mb4 collate utf8mb4_0900_ai_ci;') 
  from information_schema.schemata 
 where schema_name not in ('sys','mysql','performance_schema','information_schema') 
   and lower(default_collation_name) in ('utf8mb4_general_ci','utf8_general_ci');

調(diào)用:

/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -N < change_database_characset.sql > change_database_characset_result.sql
/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -f < change_database_characset_result.sql > change_database_characset_result.out 2>&1

2. 批量修改表字符集

change_table_characset.sql

select concat('alter table ',table_schema,'.',table_name,' default character set utf8mb4 collate = utf8mb4_0900_ai_ci;') 
  from information_schema.tables where table_schema not in ('sys','mysql','performance_schema','information_schema') 
   and table_type='BASE TABLE' and lower(table_collation) in ('utf8mb4_general_ci','utf8_general_ci');

調(diào)用:

/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -N < change_table_characset.sql > change_table_characset_result.sql
/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -f < change_table_characset_result.sql > change_table_characset_result.out 2>&1

3. 批量修改列字符集

change_column_characset.sql

set group_concat_max_len=10240;
 
select concat(c1,c2,';') 
  from (select c1, group_concat(c2) c2
          from (select concat('alter table ',t1.table_schema,'.',t1.table_name) c1,concat(' modify ','`',t1.column_name,'` ',t1.data_type,
                              if (t1.data_type in ('varchar','char'),concat('(',t1.character_maximum_length,')'),''),
                              ' character set utf8mb4 collate utf8mb4_0900_ai_ci',if(t1.is_nullable='NO',' not null',' null'),' comment ','''',t1.column_comment,'''') c2
                  from information_schema.columns t1, information_schema.tables t2
                 where t1.table_schema=t2.table_schema and t1.table_name=t2.table_name and t2.table_type='BASE TABLE' 
                   and lower(t1.collation_name) in ('utf8mb4_general_ci','utf8_general_ci') and t1.table_schema not in ('sys','mysql','performance_schema','information_schema')) t1
         group by c1) t;

調(diào)用:

/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -N < change_column_characset.sql > change_column_characset_result.sql
/home/mysql/mysql-8.0.16-linux-glibc2.12-x86_64/bin/mysql -uroot -h10.0.0.18 -P3306 -p70n6w+1XklMu -f < change_column_characset_result.sql > change_column_characset_result.out 2>&1

到此這篇關(guān)于MySQL8 批量修改字符集腳本的文章就介紹到這了,更多相關(guān)MySQL8批量修改字符集內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Prometheus 插件mysql_exporter安裝過(guò)程

    Prometheus 插件mysql_exporter安裝過(guò)程

    mysql_exporter是用來(lái)收集MysQL或者M(jìn)ariadb數(shù)據(jù)庫(kù)相關(guān)指標(biāo)的,mysql_exporter需要連接到數(shù)據(jù)庫(kù)并有相關(guān)權(quán)限,這篇文章主要介紹了Prometheus插件安裝(mysql_exporter),需要的朋友可以參考下
    2023-06-06
  • mysql中datetime類型設(shè)置默認(rèn)值方法

    mysql中datetime類型設(shè)置默認(rèn)值方法

    下面小編就為大家分享一篇mysql中datetime類型設(shè)置默認(rèn)值方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • 重置mysql的root密碼最簡(jiǎn)單的方法

    重置mysql的root密碼最簡(jiǎn)單的方法

    在本篇文章里小編給大家整理的是關(guān)于重置mysql的root密碼最簡(jiǎn)單的方法,需要的朋友們參考下。
    2020-03-03
  • 淺談mysql密碼遺忘和登陸報(bào)錯(cuò)的問(wèn)題

    淺談mysql密碼遺忘和登陸報(bào)錯(cuò)的問(wèn)題

    下面小編就為大家?guī)?lái)一篇淺談mysql密碼遺忘和登陸報(bào)錯(cuò)的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • MySQL 優(yōu)化設(shè)置步驟

    MySQL 優(yōu)化設(shè)置步驟

    mysql的一些運(yùn)行效率等優(yōu)化設(shè)置,建議擁有服務(wù)器的朋友,可以測(cè)試。
    2009-03-03
  • 如何使用索引提高查詢速度

    如何使用索引提高查詢速度

    本篇文章是對(duì)使用索引提高查詢速度的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • 徹底刪除MySQL步驟介紹

    徹底刪除MySQL步驟介紹

    大家好,本篇文章主要講的是徹底刪除MySQL步驟介紹,感興趣的趕緊來(lái)看看吧,對(duì)你有幫助的話記得收藏一下,方便下次瀏覽
    2021-12-12
  • MySQL修改時(shí)區(qū)的方法圖文詳解

    MySQL修改時(shí)區(qū)的方法圖文詳解

    這篇文章主要給大家介紹了關(guān)于MySQL修改時(shí)區(qū)的相關(guān)資料,時(shí)區(qū)是MySQL中非常重要的概念,正確設(shè)置時(shí)區(qū)可以確保應(yīng)用程序工作正常并避免時(shí)間錯(cuò)誤,文中通過(guò)圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-09-09
  • 分析一條sql的性能的標(biāo)準(zhǔn)總結(jié)

    分析一條sql的性能的標(biāo)準(zhǔn)總結(jié)

    在本篇文章里小編給各位分享了關(guān)于分析一條sql的性能的相關(guān)知識(shí)點(diǎn)總結(jié)內(nèi)容,有興趣的朋友們學(xué)習(xí)下。
    2019-07-07
  • MySQL Workbench安裝及使用詳解

    MySQL Workbench安裝及使用詳解

    MySQL是一種關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),關(guān)系數(shù)據(jù)庫(kù)將數(shù)據(jù)保存在不同的表中,而不是將所有數(shù)據(jù)放在一個(gè)大倉(cāng)庫(kù)內(nèi),這樣就增加了速度并提高了靈活性,這篇文章主要介紹了MySQL Workbench安裝及使用,需要的朋友可以參考下
    2022-10-10

最新評(píng)論