比如GBK alter table charset GBK 不过你就算改了表的编码,现有的数据还是不会变的。 这个影响的只是未来的记录数据。
正如楼上所说的,只能改变未来的新数据罢啦 如你确实要批量更改某库下的所有表的编码,则可以写个存储过程来循环调度,如下:接口: DROP PROCEDURE IF EXISTS sp_alter_db_charset; CREATE PROCEDURE `sp_alter_db_charset`(in i_dbname varchar(50)) begin declare v_i int default 0; declare v_tbname varchar(100); declare cur_test cursor for select table_name from information_schema.tables where table_schema=i_dbname; declare continue handler for not found set v_i=1; open cur_test; fetch cur_test into v_tbname; while v_i=0 do set @str=concat('alter table ',v_tbname,' charset gbk'); prepare stmt1 from @str; execute stmt1; deallocate prepare stmt1; fetch cur_test into v_tbname; end while; close cur_test; end;调用: call sp_alter_db_charset('库名');
alter table charset GBK
不过你就算改了表的编码,现有的数据还是不会变的。 这个影响的只是未来的记录数据。
如你确实要批量更改某库下的所有表的编码,则可以写个存储过程来循环调度,如下:接口:
DROP PROCEDURE IF EXISTS sp_alter_db_charset;
CREATE PROCEDURE `sp_alter_db_charset`(in i_dbname varchar(50))
begin
declare v_i int default 0;
declare v_tbname varchar(100);
declare cur_test cursor for select table_name from information_schema.tables where table_schema=i_dbname;
declare continue handler for not found set v_i=1;
open cur_test;
fetch cur_test into v_tbname;
while v_i=0 do
set @str=concat('alter table ',v_tbname,' charset gbk');
prepare stmt1 from @str;
execute stmt1;
deallocate prepare stmt1;
fetch cur_test into v_tbname;
end while;
close cur_test;
end;调用:
call sp_alter_db_charset('库名');