首页
注册
登录
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请
登录
推荐学习书目
›
Learn Python the Hard Way
Python Sites
›
PyPI
- Python Package Index
›
http://diveintopython.org/toc/index.html
›
Pocoo
值得关注的项目
›
PyPy
›
Celery
›
Jinja2
›
Read the Docs
›
gevent
›
pyenv
›
virtualenv
›
Stackless Python
›
Beautiful Soup
›
结巴中文分词
›
Green Unicorn
›
Sentry
›
Shovel
›
Pyflakes
›
pytest
Python 编程
›
pep8 Checker
Styles
›
PEP 8
›
Google Python Style Guide
›
Code Style from The Hitchhiker's Guide
V2EX
›
Python
pymysql 执行报错,大佬们帮忙看看
gyy028012
·
2020-11-27 16:43:03 +08:00
· 1712 次点击
这是一个创建于 1409 天前的主题,其中的信息可能已经有所发展或是发生改变。
使用 pymysql 的 execute 方法执行 SQL 语句
SQL 语句如下:
SET @
days
:= 10;
SELECT @
days
as 'days';
报语法错误
(1064, "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 'SELECT @
days
AS 'days'' at line 4")
这个 SQL 语句在 navicat 上是可以执行的
有大佬帮忙指点迷津吗
SQL
语句
pymysql
select
3 条回复
•
2020-11-30 17:18:04 +08:00
1
smallpython
2020-11-27 18:15:42 +08:00
想问下这个语法是什么含义
2
tmackan
2020-11-27 18:21:35 +08:00
贴下你的 py 代码应该,
如上 sql 直接到 mysql 执行是没问题的
@
smallpython
设置个运行时全局变量而已
3
gyy028012
OP
2020-11-30 17:18:04 +08:00
@
tmackan
代码是这样的:
(我觉得不是 py 代码的问题,因为其他的 SQL 语句是可以运行的,可能是这个 SQL 里面有两个分号导致的)
sql ="""
SET @
days
:= 10;
SELECT @
days
as 'days';
"""
conn = pymysql.connect(host, port,user,password,database,charset="utf8")
cur = conn.cursor()
cur.execute(sql)
conn.commit()
关于
·
帮助文档
·
博客
·
API
·
FAQ
·
实用小工具
·
1739 人在线
最高记录 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 27ms ·
UTC 00:20
·
PVG 08:20
·
LAX 17:20
·
JFK 20:20
Developed with
CodeLauncher
♥ Do have faith in what you're doing.