今天在玩一个web的项目时,遇到了这么一个问题,go中使用insert into命令插入记录时,没有报错,但是在数据库中却没有成功,一开始我以为是post请求时获取数据出了问题,但是多次测试过后,发现没有问题,又多次打印error,到处调试,但总是没有发现问题所在。之后偶然post数据时我随便乱按键盘,随便一看竟然成功了,这时我才突然有了想法,我是最近用linux的,并没有考虑转码问题,同时在go中打开数据库时也转码了utf-8了,以为没有问题,这时候我进入mysql随便插入中文,发现没有成功,这才找到问题所在。下次遇到这个问题要注意创建table时设置一下编码。

解决:

  1. 创建的时候转码
create table entries2 (
        id     int auto_increment, 
        title  text,
        content  text,
        posted_on  datetime,
        primary key (id)   
) character set = utf8;
  1. 转换已有table
    alter table table_name convert to character set utf8;

参考:
https://www.cnblogs.com/livingintruth/p/3433259.html

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2021-11-19
  • 2021-04-13
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2021-10-26
猜你喜欢
  • 2022-01-10
  • 2022-12-23
  • 2022-12-23
  • 2021-04-10
  • 2021-06-14
  • 2021-06-09
  • 2021-09-28
相关资源
相似解决方案