mysql数据库编码设置成utf-8,避免出现乱码

时间:2022-09-12 22:42:59

设置默认编码为utf8:
set names utf8;
设置数据库db_name默认为utf8:
ALTER DATABASE `db_name` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
设置表tb_name默认编码为utf8:
ALTER TABLE `tb_name`        DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;