Python MySQL OperationalError: (1054, "Unknown column 'XX' in 'where clause'")
2014-03-11 17:52
1081 查看
问题症状和这里的类似,直接在SQL语句用%拼接string会出现
OperationalError: (1054, "Unknown column 'XX' in 'where clause'")错误,使用2.6+版本的Python最好使用format方法,如下:
SQL语句:
run_sql.sql:
使用Python连接实例:
这样就不会出错了。
OperationalError: (1054, "Unknown column 'XX' in 'where clause'")错误,使用2.6+版本的Python最好使用format方法,如下:
SQL语句:
run_sql.sql:
create database name; create table just_id_and_name ( id integer primary key auto_increment, name varchar(200) not null ); use name; insert into just_id_and_name (name) values ('Jerry'); insert into just_id_and_name (name) values ('Jim'); insert into just_id_and_name (name) values ('Tom'); insert into just_id_and_name (name) values ('Lee');
使用Python连接实例:
import MySQLdb conn = MySQLdb.connect(host='127.0.0.1', user='root', passwd='', db="name") cur = conn.cursor() data = 'Tom' query = "select * from just_id_and_name where name = '{0}'".format(data) print query cur.execute(query) res = cur.fetchone() print res
这样就不会出错了。
相关文章推荐
- 执行廖雪峰老师案例时出现的问题【pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1'"】
- django操作mysql时django.db.utils.OperationalError: (2003, "Can't connect to MySQL server")错误的解决办法
- django.db.utils.OperationalError: (1050, "Table 'devtypeinfo' already exists
- mysql 5.7 版本,密码无法登陆,更改密码时出现ERROR 1054 (42S22): Unknown column 'password' in 'fie
- django.db.utils.OperationalError: (1049, "Unknown database "test_django_mysql")的解决办法
- mac下安装mysql-python包报unable to execute llvm-gcc-4.2: No such file or directory error: command 'llvm-g
- Python MySQL 1054 "Unknown column '\xe7\x88\xb1\xe6\x83\x85' in 'where clause'"错误分析
- ubuntu 安装mysql 错误Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-lmPxC
- ERROR 1054 (42S22): Unknown column 'plugin' in 'mysql.user'
- Python插入数据到mysql:1054, "Unknown column 'CNITSEC2014SRV' in 'field list'"
- TypeError: iter() returned non-iterator of type 'xx' 从Python3开始,要用__next__
- Mysql创建用户出错:ERROR 1054 (42S22): Unknown column 'plugin' in 'mysql.user'
- python __def__ Exception AttributeError: "'NoneType' object has no attribute
- django数据迁移发生django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'loca lhost'
- 安装MySQL-python时发生错误:error: command 'gcc' failed with exit status 1
- pymysql.err.InternalError: (1054, "Unknown column 'None' in 'field list'")
- python脚本处理文本时遇到的字符问题:UnicodeDecodeError: " " codec can't decode byte
- mysql-Can\'t connect to MySQL server on \'127.0.0.1\' (10061) (code 2003)"): error calling Python mo
- django操作mysql时django.db.utils.OperationalError: (2003, "Can't connect to MySQL server")异常的解决方法