Convert UTF8 character columns in a MySQL database to GBK format _ MySQL

Source: Internet
Author: User
Convert UTF8 character columns in a MySQL database to bitsCN.com in GBK format.

Convert UTF8 character columns in a MySQL database to GBK format.

DELIMITER $$DROP PROCEDURE IF EXISTS `dba`.`Proc_ChangeCharacter2GBK`$$CREATE DEFINER=`root`@`%` PROCEDURE ` Proc_ChangeCharacter2GBK`(in DATABASENAME varchar(20))BEGIN    DECLARE done INT DEFAULT 0;    DECLARE a VARCHAR(64) DEFAULT '';    DECLARE b VARCHAR(64) DEFAULT '';    DECLARE c VARCHAR(64) DEFAULT '';    DECLARE d VARCHAR(64) DEFAULT '';    DECLARE l_sql VARCHAR(500);        DECLARE AlterColumnsCharacter CURSOR FOR            SELECT TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME,COLUMN_TYPE            FROM information_schema.COLUMNS            WHERE TABLE_SCHEMA=DATABASENAME                 and TABLE_NAME in (  SELECT B.TABLE_NAME FROM information_schema.TABLES B                                                          WHERE B.TABLE_SCHEMA=DATABASENAME  AND B.TABLE_TYPE='BASE TABLE' )                  and COLUMN_TYPE like '%VARCHAR%' and CHARACTER_SET_NAME='utf8' and COLLATION_NAME='utf8_general_ci';    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done=1;      OPEN AlterColumnsCharacter;      REPEAT  FETCH AlterColumnsCharacter INTO a,b,c,d;    if(done = 0) then       SET l_sql=CONCAT(' alter table ',a, '.',b,' change ',c,' ',c,' ',d,' character set gbk collate gbk_chinese_ci NULL; ');       SET @sql=l_sql;      PREPARE s1 FROM @sql;      EXECUTE s1;      DEALLOCATE PREPARE s1;    end if;           UNTIL done     END REPEAT;    CLOSE AlterColumnsCharacter;    END$$DELIMITER ;


BitsCN.com

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.