标签: mysql-python

MySQLdbexecutemany不添加数据

我正在尝试使用 MySQLdbexecutemany 命令将数据添加到表(test_copy),如下所示:

db = mdb.connect(host="127.0.0.1",port=3306,user='XXXX',db="test")
cursor = db.cursor()
COM = "insert into test_copy (Short_Model) VALUES (%s)"
VALS = ['213','3232','fd','sadad']
cursor.executemany(COM,VALS)
cursor.close
Run Code Online (Sandbox Code Playgroud)

注意:表名称 = test_copy,列名称 = Short_Model

问题是该命令运行时没有任何错误,但当我检查表时没有添加数据。

如果这是一个简单的问题,我深表歉意,但在过去的几个小时里它让我发疯。

谢谢。

python mysql mysql-python

4
推荐指数
1
解决办法
3894
查看次数

Python 中的 MySQL 连接器不允许 LOAD DATA INFILE 语法

我正在尝试将文本文件发送到 MySQL 数据库。我正在尝试使用 python 3.2 中的 mysql 连接器来执行此操作。问题与 LOAD DATA INFILE 语法有关。你可以在上面找到我的代码。我的第一个问题是有没有办法解决这个问题。请注意,我尝试过 local-infile =1 选项,但 Python 不允许此选项。其次,有没有其他方法可以将这些数据作为一个块发送到mysql数据库中?

from __future__ import print_function
import os
import mysql.connector
from mysql.connector import errorcode
config = {
    'user':'root',
    'password':'3778',
##  'host':'localhost',
#   'database':'microstructure',
#    'local-infile':'1',
    }


DB_NAME = 'EURUSD'
TABLES ={}
TABLES['microstructure']=(
    "CREATE TABLE `microstructure` ("
   # "  `p_id` int NOT NULL AUTO_INCREMENT,"
    "  `ticker` varchar(255),"
    "  `time` date,"
    "  `last_price` decimal(6,3)"
    ") ENGINE=InnoDB")

TABLES['cumulative']=(
    "CREATE TABLE `cumulative` ("
    "  `p_id` int NOT NULL AUTO_INCREMENT," …
Run Code Online (Sandbox Code Playgroud)

python mysql-python

4
推荐指数
1
解决办法
1万
查看次数

数据被插入 MySQL 但并未永久保存 - Python

我用来MySQLdb操作MySQL数据库,并且我有以下例程,将一些数据注入名为的表中urls:

def insert_urls(dbconn, filenames):
    root = "<path>/"
    link = "http://<url>/"
    for f in filenames:
        filename = root + f + ".html"
        local_url = link + f + ".html"
        print(filename, local_url)
        sql = """
        INSERT INTO urls(url, filename) VALUES('%s', '%s');
        """ % (local_url, filename)
        print(sql)
        dbconn.execute_query(sql)
Run Code Online (Sandbox Code Playgroud)

该表的声明urls可以在这里找到:

def create_urls_table():

    sql = """
        CREATE TABLE IF NOT EXISTS urls (
            id INT NOT NULL AUTO_INCREMENT,
            url BLOB NOT NULL,
            filename BLOB NOT NULL,
            PRIMARY …
Run Code Online (Sandbox Code Playgroud)

python mysql mysql-python

4
推荐指数
1
解决办法
1942
查看次数

ModuleNotFoundError:没有名为“MySQLdb”的模块 Amazon MySQL RDS SQLAlchemy

我在将 Amazon AWS MySQL 与 SQLAlchemy 连接时遇到问题。按照提示,我已经连接了。

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://<user>:<password>@<host>/<dbname>
Run Code Online (Sandbox Code Playgroud)

但有一个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ec2-user/venv/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 514, in __get__
    return type.query_class(mapper, session=self.sa.session())
  File "/home/ec2-user/venv/lib/python3.7/site-packages/sqlalchemy/orm/scoping.py", line 74, in __call__
    return self.registry()
  File "/home/ec2-user/venv/lib/python3.7/site-packages/sqlalchemy/util/_collections.py", line 1001, in __call__
    return self.registry.setdefault(key, self.createfunc())
  File "/home/ec2-user/venv/lib/python3.7/site-packages/sqlalchemy/orm/session.py", line 2950, in __call__
    return self.class_(**local_kw)
  File "/home/ec2-user/venv/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 143, in __init__
    bind = options.pop('bind', None) or db.engine
  File "/home/ec2-user/venv/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 877, in engine
    return self.get_engine()
  File "/home/ec2-user/venv/lib/python3.7/site-packages/flask_sqlalchemy/__init__.py", line 896, …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy mysql-python amazon-web-services

4
推荐指数
1
解决办法
3730
查看次数

Python MySQL 连接器不支持 SSL

我最近在我的 MySQL 服务器上配置了 SSL,它似乎破坏了我的 python 应用程序。我可以通过命令行很好地连接到服务器:

user@kiosk:~$ mysql -u <user> -p -h <remote host>
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current …
Run Code Online (Sandbox Code Playgroud)

python mysql mysql-python python-2.7

4
推荐指数
1
解决办法
2万
查看次数

命令“python setup.py egg_info”在 /tmp/pip-build-tu6ygqzj/mysql-python/ 中失败,错误代码为 1

我正在使用 python3 安装 mysql-python 包。所以,当我跑

pip 安装 mysql-python,

它给了我错误。

尝试使用

pip install --upgrade 安装工具

表明

Collecting mysql-python
  Using cached https://files.pythonhosted.org/packages/a5/e9/51b544da85a36a68debe7a7091f068d802fc515a3a202652828c73453cad/MySQL-python-1.2.5.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-tu6ygqzj/mysql-python/setup.py", line 13, in <module>
        from setup_posix import get_config
      File "/tmp/pip-build-tu6ygqzj/mysql-python/setup_posix.py", line 2, in <module>
        from ConfigParser import SafeConfigParser
    **ImportError: No module named 'ConfigParser'**

----------------------------------------
***Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-tu6ygqzj/mysql-python/***
Run Code Online (Sandbox Code Playgroud)

成功安装,其中包含所有文件。

python pip mysql-python

4
推荐指数
1
解决办法
2万
查看次数

Django select_for_update 中的锁定记录是否受到更新值的影响

我知道如果我们有多个并发用户, select_for_update 会锁定正在查询的记录。但是否也影响对查询记录的评估。

例如,如果用户 A 和用户 B 基于单个布尔变量“Available”同时查询表“Jobs”。两个用户都想访问可用职位的记录(其中Available = True)。

用户 A 设法先排队,并且他正在访问的记录现在已为用户 B 锁定。

如果用户A将所有记录都更改为False,那么用户B是否不会获取任何记录?或者他是否获得与用户 A 相同的记录,但可用性等于 False?

另外, select_for_update() 是否适用于 MySQL?或者对于并发查询有不同的解决方案吗?

mysql django concurrency mysql-python isolation-level

4
推荐指数
1
解决办法
4259
查看次数

安装 MySQL-python 失败

我想在 python 2.7 虚拟环境中安装 MySQL-python,但出现以下错误:

Installing collected packages: MySQL-python
Running setup.py install for MySQL-python ... error
ERROR: Command errored out with exit status 1:
 command: /home/jhylands/py2/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-scNGlE/MySQL-python/setup.py'"'"'; __file__='"'"'/tmp/pip-install-scNGlE/MySQL-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-FUMQGL/install-record.txt --single-version-externally-managed --compile --install-headers /home/jhylands/py2/include/site/python2.7/MySQL-python
     cwd: /tmp/pip-install-scNGlE/MySQL-python/
Complete output (30 lines):
running install
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying _mysql_exceptions.py -> build/lib.linux-x86_64-2.7
creating build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/__init__.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/converters.py -> build/lib.linux-x86_64-2.7/MySQLdb
copying MySQLdb/connections.py …
Run Code Online (Sandbox Code Playgroud)

python mysql mysql-python python-2.7

4
推荐指数
2
解决办法
1565
查看次数

无法在Lion/Mountain Lion上安装python-mysql

我花了整整两天的时间试图让python-mysql去年彻底安装Lion,最后绝望地放弃了.升级到Mountain Lion之后,我想我会再试一次,但没有成功.可能是我对Lion的所有尝试都搞砸了我的设置,我唯一的希望是干净安装,但万一有人可以救我,这里有症状.

首先,我删除了仍然存在的三个版本:

/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-i386.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-i386.egg-tmp/_mysql.so
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-intel.egg-tmp/_mysql.so
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-x86_64.egg-tmp
/Users/phoebebr/.python-eggs/MySQL_python-1.2.3-py2.7-macosx-10.7-x86_64.egg-tmp/_mysql.so
Run Code Online (Sandbox Code Playgroud)

然后重新安装.一切似乎都没问题,但有警告,似乎是64位版本:

    Phoebe-Brights-iMac:.python-eggs phoebebr$ sudo pip install mysql-python
    dyld: DYLD_ environment variables being ignored because main executable (/usr/bin/sudo) is setuid or setgid
    Password:
    Downloading/unpacking mysql-python
      Downloading MySQL-python-1.2.4c1.zip (113kB): 113kB downloaded
      Running setup.py egg_info for package mysql-python
        Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz
        Extracting in /tmp/tmp7fFOxU
        Now working in /tmp/tmp7fFOxU/distribute-0.6.28
        Building a Distribute egg in /private/tmp/pip-build/mysql-python
        /private/tmp/pip-build/mysql-python/distribute-0.6.28-py2.7.egg

    Installing collected packages: mysql-python
      Running setup.py install for mysql-python
        building '_mysql' extension
        clang -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common …
Run Code Online (Sandbox Code Playgroud)

mysql-python osx-mountain-lion

3
推荐指数
1
解决办法
3836
查看次数

UnboundLocalError:赋值前引用的局部变量'cursor'

所以我是一个新手但是正在使用flask/MYSQL中的注册系统表单

我收到此错误(UnboundLocalError:赋值前引用的局部变量'cursor')

经过几个小时的代码和研究,我需要你的帮助.

这是我的档案,如果我需要分享其他任何内容,请告诉我.谢谢

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.config['MYSQL_DATABASE_USER'] = 'x'
app.config['MYSQL_DATABASE_PASSWORD'] = 'x'
app.config['MYSQL_DATABASE_DB'] = 'x'
app.config['MYSQL_DATABASE_HOST'] = 'x'
mysql.init_app(app)

@app.route('/')
def main():
    return render_template('index.html')

@app.route('/login')
def login():
    return render_template('login.html')

@app.route('/showSignUp')
def showSignUp():
    return render_template('signup.html')


@app.route('/signUp',methods=['POST','GET'])
def signUp():
    try:
        _name = request.form['inputName']
        _email = request.form['inputEmail']
        _password = request.form['inputPassword']

        # validate the received values
        if _name and _email and _password:

            # All …
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy mysql-python flask

3
推荐指数
2
解决办法
7283
查看次数