我正在使用PyMySQL-0.5.0,并且在将数据从文件加载到远程MySQL实例时遇到晦涩的错误/异常。在执行“LOAD DATA LOCAL INFILE ...”语句中,我看到上面写着一个例外:The used command is not allowed with this MySQL version。
任何提示,如果PyMySQL完全支持此操作(和/或其他一些版本支持)
PS:
1)错误详细信息:
2012-05-17 11:05:24,524 - 8988 - DEBUG - Loading table table_2012_05_16
from file: /path/to/data/file_2012-05-16
2012-05-17 11:05:24,524 - 8988 - DEBUG - Executing update: load data local
infile '/path/to/data/file_2012-05-16' into table table_2012_05_16(@dummy, c1,
c2, c3, c4, c5, c6, c7);
2012-05-17 11:05:24,528 - 8988 - ERROR - Exception while executing update:
<class 'pymysql.err.InternalError'> - (1148, u'The used command is not allowed
with …Run Code Online (Sandbox Code Playgroud) 我使用mysqldb插入一行:
def insertNewLog(self,uid,beginDate,endDate,logs):
qry1 = """INSERT INTO logs (owner,createDate,endDate,log) VALUES (%s,%s,%s,%s); """
cursor = self.db.cursor()
beginDate = int(time.mktime( beginDate.timetuple() ))
endDate = int(time.mktime( endDate.timetuple()))
print beginDate
print endDate
cursor.execute(qry1,(uid,beginDate,endDate,logs),)
print "inserted normally"
print "Number of rows inserted: %d" % cursor.rowcount
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
1337720045
1337740625
inserted normally
Number of rows inserted: 1
Run Code Online (Sandbox Code Playgroud)
但是当我在mysql shell中选择我的数据库时,我得到'空集'.我检查我的mysql日志,那里没有任何报告.我有点困惑.
虽然这个问题以前有人问在这里,被张贴的问题和后续的答案有相关的OS X(雪豹),而不是OS X狮子和OS X山狮.OS X Lion和OS X Mountain Lion中提供了Python和MySQL的补丁,这些补丁影响了在Mac OS X 10.7(Lion)和Mac OS X 10.8(Mountain Lion)上顺利安装Python-MySQLdb-connector的过程.这是重复这个问题的唯一原因.如果您运行的是旧版OS X,请随时参考旧问题.
我正在运行OS X 10.8.2(Mountain Lion)并安装了python 2.7.2 -
==> python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Run Code Online (Sandbox Code Playgroud)
但是当我在python上运行导入MySQLdb时,它失败并显示以下消息 -
==> python
Python 2.7.2 (default, Jun 20 2012, 16:23:33)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" …Run Code Online (Sandbox Code Playgroud) 在使用MySQLdb的python中,我试图执行以下操作:
cur.execute("select COUNT(*) from adjacency where r = %d and c = %d)" % (curRow, curCol)
Run Code Online (Sandbox Code Playgroud)
r并且c是表中的整数字段,adjacency并且还形成复合主键.curRow并且curCol是我的python程序中的整数变量.MySQL抱怨:
_mysql_exceptions.ProgrammingError: (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 '%d and c = %d' at line 1")
Run Code Online (Sandbox Code Playgroud)
最后,我想检查是否已存在与r=curCow和相邻的行c=curCol.如果是,则更新表中的字段.否则在表中插入一行.
非常感谢所有帮助!
使用以下方法从MySQL数据库获取一些数据:
cur.execute("SELECT memory FROM vm WHERE hv_id=5")
for row in cur.fetchall() :
print row[0]
Run Code Online (Sandbox Code Playgroud)
这打印出这样的东西:
512
1024
4096
4096
2048
4096
1024
6144
1024
1024
4096
Run Code Online (Sandbox Code Playgroud)
我需要总结以上内容并将其设置为变量以进行进一步计算.
我想知道在避免重复的同时创建列表的最佳方法是什么.
我在mysql中有一些数据包含产品类型.
例如:
id ------- category
1 -------- food, drink, vege
2 -------- food, drink
3 -------- vege, baby goods
4 -------- fish
Run Code Online (Sandbox Code Playgroud)
我瞄准的输出是:
['food','drink','vege','baby goods','fish']
Run Code Online (Sandbox Code Playgroud)
(请注意订单对我来说无关紧要)
数据集有超过40,000条记录,因此手动检查肯定不是一种选择......
如果你能给我一个说明或建议,我将不胜感激.
目前我正在使用以下代码在 mysql 中创建一个表。
CREATE TABLE example(id INT, ts TIMESTAMP DEFAULT CURRENT_TIMESTAMP);
因此,每当我将数据插入到该表中时,我都会得到 (YEAR-MONTH-DATE HOURS-MINUTE-SECOND) 格式的 ts 值,并且我想以 (DATE-MONTH-YEAR HOURS-MINUTE-SECOND) 格式更改它,让我们假设我已使用以下方法在上面创建的表中插入了数据
insert into example (id) values (123);
当我使用检索信息时
select * from example;
+------+---------------------+
| id | ts |
+------+---------------------+
| 123 | 2014-07-28 17:17:10 |
+------+---------------------+
我得到这种格式的日期时间2014-07-28 17:17:10,我想将其更改为28-07-2014 17:17:10,是否可以更改时间戳的格式?如果是的话我们该怎么做呢?
您好,我正在按照在线教程构建 Flask Web 应用程序,当我尝试通过注册按钮将信息存储到我的数据库中时,不断遇到此错误。
from flask import Flask, render_template, json, request
from flask.ext.mysqldb import MySQL
from werkzeug import generate_password_hash, check_password_hash
app = Flask(__name__)
mysql = MySQL(app)
# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = 'pass'
app.config['MYSQL_DATABASE_DB'] = 'table'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)
@app.route("/")
def main():
return render_template('index.html')
@app.route('/showSignUp')
def showSignUp():
return render_template('signup.html')
@app.route('/signUp', methods = ['POST','GET' ])
def signUp():
_phonenumber = request.form['phonenumber']
_name = request.form['name']
_password = request.form['password']
if _phonenumber and _name and _password:
conn = mysql.connect()
cursor = conn.cursor() …Run Code Online (Sandbox Code Playgroud) 我现在正在尝试在 SQLAlchemy 中从旧课程中实现非常简单的示例表...
我已经走了这么远但是当我运行代码时......
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Date, MetaData
from sqlalchemy import ForeignKey
from sqlalchemy.orm import relationship
from sqlalchemy import create_engine
Base = declarative_base()
engine = create_engine('mysql://x @ amazonaws.com:3306/db', echo=True)
class Guest(Base):
__tablename__ = "guests"
guest_no = Column(String(4), primary_key=True)
g_name = Column(String(20))
g_address = Column(String(30))
booking = relationship("Booking", back_populates="guests")
class Hotel(Base):
__tablename__ = "hotels"
hotel_no = Column(String(4), primary_key=True)
h_name = Column(String(20))
h_address = Column(String(30))
room = relationship("Room", back_populates="hotels")
booking = relationship("Booking", back_populates="hotels")
class …Run Code Online (Sandbox Code Playgroud) 我试图使用mysql连接器python连接到mysql数据库。我的桌子是拉丁编码的。我或多或少从文档中尝试过此方法:
from mysql.connector import (connection)
cnx = connection.MySQLConnection(user='scott', password='password',
host='127.0.0.1',
database='employees')
cnx.close()
Run Code Online (Sandbox Code Playgroud)
但是我得到了错误:
ERROR 1115 (42000): Unknown character set: 'utf8mb4'
Run Code Online (Sandbox Code Playgroud)
为什么utf8mb4我的表是拉丁编码的?
mysql-python ×10
python ×9
mysql ×6
append ×1
flask ×1
join ×1
select ×1
sql ×1
sqlalchemy ×1
string ×1