推荐学习书目
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
gyy028012
V2EX  ›  Python

pymysql 执行报错,大佬们帮忙看看

  •  
  •   gyy028012 · Nov 27, 2020 · 2432 views
    This topic created in 2020 days ago, the information mentioned may be changed or developed.
    使用 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 上是可以执行的

    有大佬帮忙指点迷津吗
    3 replies    2020-11-30 17:18:04 +08:00
    smallpython
        1
    smallpython  
       Nov 27, 2020
    想问下这个语法是什么含义
    tmackan
        2
    tmackan  
       Nov 27, 2020
    贴下你的 py 代码应该,
    如上 sql 直接到 mysql 执行是没问题的
    @smallpython 设置个运行时全局变量而已
    gyy028012
        3
    gyy028012  
    OP
       Nov 30, 2020
    @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()
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3126 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:42 · PVG 22:42 · LAX 07:42 · JFK 10:42
    ♥ Do have faith in what you're doing.