Mysql常见使用问题的解决方法

问题一:Mysql插入中文数据时,报错“incorrect string value”字符转换不正确

解决方法:

第一种方式:

1.更改Mysql安装目录下的文件my.ini(一般在隐藏文件夹ProgramData\Mysql\MySQL Server xx下),没有则自己创建

2.添加以下字符(注意文件中已有的不要重复添加):

  [mysqld]
  character-set-server=utf8mb4
  [mysql]
  default-character-set=utf8mb4

3.重启Mysql服务

4.将已经建好的表转换为utf8mb4格式:

  alter table 表名 convert to character set utf8mb4 collate utf8mb4_bin;

第二种方式:

1.用命令将数据库转换为utf8mb4格式:

  alter database 数据库名  character set utf8mb4 collate utf8mb4_general_ci;

2.将已经建好的表转换为utf8mb4格式:

  alter table 表名 convert to character set utf8mb4 collate utf8mb4_bin;

 

posted @ 2022-10-12 11:27  昨天忆  阅读(117)  评论(0编辑  收藏  举报