在线精品99_中国九九盗摄偷拍偷看_91免费版在线观看_91.app_91高清视频在线_99热最新网站

如何进行MYSQL特殊字符的处理

133次阅读
没有评论

共计 4114 个字符,预计需要花费 11 分钟才能阅读完成。

这篇文章给大家介绍如何进行 MYSQL 特殊字符的处理,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

单引号,以及行尾的斜杠引起的困惑:

这一次的问题,我们直接从实际的工作中说起:

工作内容简介:有一批用户 ID 存在文件里,需要从数据库里删除?

做这个事情,可能有很多的方法:
1,把 ID 导入到数据库中,用 SQL 直接做表关联去删除;
2,用 SHELL(或其他语言)写个小程序,根据文件里的 ID 做一个 FOR 循环,然后在 MYSQL 中去删除;
3,用 sed 直接把 ID 转成 delete 语句,完了直接运行即可;

[@more@]

由于数据量较大(1.6 亿),显然,我会用偷懒以及简单的方法 3:
———————————————-
[root@im_ctuallot1 tmp]# cat loginid.txt
xouqun76818
ogku15mtb7c
[email protected]
曾朴绍 283902
轻舞飞扬 061129 付了

[root@im_ctuallot1 tmp]# sed  -e s/^/delete from ctulog.db_allot_center_64 where long_id= /g -e s/$/ /g  loginid.txt loginid.sql
[root@im_ctuallot1 tmp]# cat loginid.sql
delete from ctulog.db_allot_center_64 where long_id= xouqun76818
delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
delete from ctulog.db_allot_center_64 where long_id= [email protected]
delete from ctulog.db_allot_center_64 where long_id= 曾朴绍 283902
delete from ctulog.db_allot_center_64 where long_id= 轻舞飞扬 061129 付了

mysql -uroot -h227.0.0.1 –default-character-set=latin1  –force ctulogdb loginid.sql

–force 是防止某个 SQL 出现错误,而导致整个任务终止;
———————————————

搞定。
这看似非常简单的方法,也暴露出很多的问题,结果 1.6 行数据只成功删除了 3300W, 任务失败;
其实是我把这个任务想得太简单了:在用户 ID 中存在任何可能的字符,如:
bao pijkl
tingting831118

注意,在用户 ID 中有 , 在行末尾有: 
我们把这样的语句渗杂到其他 ID 中,我们看会有怎么的效果;

[root@im_ctuallot1 tmp]# cat loginid.txt
xouqun76818
bao pijkl
ogku15mtb7c
[email protected]
曾朴绍 283902
tingting831118
轻舞飞扬 061129 付了

[root@im_ctuallot1 tmp]# sed  -e s/^/delete from ctulog.db_allot_center_64 where long_id= /g -e s/$/ /g  loginid.txt loginid.sql
[root@im_ctuallot1 tmp]# cat loginid.sql
delete from ctulog.db_allot_center_64 where long_id= xouqun76818
delete from ctulog.db_allot_center_64 where long_id= bao pijkl
delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
delete from ctulog.db_allot_center_64 where long_id= [email protected]
delete from ctulog.db_allot_center_64 where long_id= 曾朴绍 283902
delete from ctulog.db_allot_center_64 where long_id= tingting831118
delete from ctulog.db_allot_center_64 where long_id= 轻舞飞扬 061129 付了

[root@im_ctuallot1 tmp]# mysql -uroot -h227.0.0.1 –default-character-set=latin1  –force ctulog loginid.sql
ERROR at line 2: Unknown command .
ERROR 1064 (42000) at line 2: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near pijkl
delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
delet at line 1

会出现一堆这样的错误;
如果你手动把以上 SQL 贴到 MYSQL 中去执行:
[email protected] : ctulog 15:59:04
[email protected] : ctulog 15:59:04 delete from ctulog.db_allot_center_64 where long_id= xouqun76818
Query OK, 0 rows affected (0.00 sec)

[email protected] : ctulog 15:59:05 delete from ctulog.db_allot_center_64 where long_id= bao pijkl
    delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
    delete from ctulog.db_allot_center_64 where long_id= [email protected]
    delete from ctulog.db_allot_center_64 where long_id= 曾朴绍 283902
    delete from ctulog.db_allot_center_64 where long_id= tingting831118
ERROR:
Unknown command .
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near pijkl
delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
delet at line 1
[email protected] : ctulog 15:59:05 delete from ctulog.db_allot_center_64 where long_id= 轻舞飞扬 061129 付了
Query OK, 0 rows affected (0.00 sec)

[email protected] : ctulog 15:59:10

只有第一条,最后一条执行成功了;

到这里我想大家应该明白了,
最关键的是单引号的不匹配导致 MYSQL 不能正确认识完整的 SQL;
注意,在用户 ID 中,出现 单个单引号,或以 结束,都会有这个问题;

问题找到了,其实解决很简单,就是先把用户 ID 中的单引号和 $ 作一个转换:
[root@im_ctuallot1 tmp]# cat loginid.txt
xouqun76818
bao pijkl
ogku15mtb7c
[email protected]
曾朴绍 283902
tingting831118
轻舞飞扬 061129 付了
[root@im_ctuallot1 tmp]# sed -e s///g -e s/ / /g -e s/^/delete from ctulog.db_allot_center_64 where long_id= /g -e s/$/ /g  loginid.txt loginid.sql
[root@im_ctuallot1 tmp]# cat loginid.sql
delete from ctulog.db_allot_center_64 where long_id= xouqun76818
delete from ctulog.db_allot_center_64 where long_id= bao pijkl
delete from ctulog.db_allot_center_64 where long_id= ogku15mtb7c
delete from ctulog.db_allot_center_64 where long_id= [email protected]
delete from ctulog.db_allot_center_64 where long_id= 曾朴绍 283902
delete from ctulog.db_allot_center_64 where long_id= tingting831118
delete from ctulog.db_allot_center_64 where long_id= 轻舞飞扬 061129 付了
[root@im_ctuallot1 tmp]#

是这样的 SQL 执行就不会有任何问题。

就这么简单的问题,耗了 5 个小时,还是 SHARE 一下以免大家在这里浪费时间。

关于如何进行 MYSQL 特殊字符的处理就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-19发表,共计4114字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)
主站蜘蛛池模板: 亚洲二区在线播放 | 久久亚洲精品无码播放 | 四虎影院网址大全 | 久久精品中文字幕第一页 | 亚洲欧美日本综合 | 久久久亚洲欧洲日产国产成人无码 | 午夜影视在线视频观看免费 | 狠狠色噜噜狠狠狠狠97俺也去 | 日日碰天天久久 | 国产欧美日韩在线不卡第一页 | 超薄丝袜足j好爽在线观看 超黄视频网站 | 日本三级免费看 | 欧美日韩精选 | 亚洲swag精品自拍一区 | 性高湖久久久久久久久 | 黄色美女一级片 | 草草福利影院 | 在线中文字幕不卡 | 2021国产成人综合亚洲精品 | 国产在线看不卡一区二区 | 免费a级毛片无码a | 国产又猛又黄又爽 | 小视频国产| 成人a毛片免费视频观看 | 中文国产成人精品久久无广告 | 一级特黄aaa大片免色 | 青草网在线观看 | 亚洲精品一区二区三区小说 | 亚洲福利一区福利三区 | 一级日韩| 国产精品av在线 | 无码熟妇人妻av在线网站 | 国产午夜亚洲精品午夜鲁丝片 | 久久国产欧美日韩精品图片 | 大香伊蕉在人线国产最新75 | 国产日韩在线观看视频网站 | 成人福利网址永久在线观看 | 国产成人精品亚洲日本在线 | 色欲天天天综合网 | 四虎视频在线精品免费观看 | 国产在线拍揄自揄视频菠萝 |