相关疑难解决方法(0)

mysql-python安装错误:无法打开包含文件'config-win.h'

我正在尝试运行,pip install mysql-python connector但它一直给我一个错误" 无法打开包含文件:'config-win.h' ".

安装在我的Mac和另一台Windows机器上运行正常,但不是这个.我已经下载了Visual Studio C++并尝试安装32位和64位.

_mysql.c(42) : fatal error C1083: Cannot open include file: 'config-win.h': No s
uch file or directory

error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio 9.0\\VC\\BIN\\c
l.exe' failed with exit status 2

----------------------------------------
Cleaning up...
Command C:\Users\Admin1\Desktop\python\virtual\Scripts\python.exe -c "import set
uptools, tokenize;__file__='C:\\Users\\Admin1\\Desktop\\python\\virtual\\build\\
MySQL-python\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).r
ead().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\admin
1\appdata\local\temp\1\pip-6pmwrd-record\install-record.txt --single-version-ext
ernally-managed --compile --install-headers C:\Users\Admin1\Desktop\python\virtu
al\include\site\python2.7 failed with error code 1 in C:\Users\Admin1\Desktop\py
thon\virtual\build\MySQL-python
Storing debug log for …
Run Code Online (Sandbox Code Playgroud)

python mysql failed-installation mysql-python

69
推荐指数
6
解决办法
10万
查看次数

如何使用sqlalchemy创建db mysql

我需要使用sqlalchemy在mysql中创建一个db,如果它已经存在,我可以连接到db,但是我希望能够创建它,如果它不存在的话.这是我的表:

    #def __init__(self):
Base = declarative_base()

class utente(Base):
    __tablename__="utente"
    utente_id=Column(Integer,primary_key=True)
    nome_utente=Column(Unicode(20))
    ruolo=Column(String(10))
    MetaData.create_all()

    def __repr(self):
        return "utente: {0}, {1}, id: {2}".format(self.ruolo,self.nome_utente,self.utente_id)


class dbmmas(Base):

    __tablename__="dbmmas"
    db_id=Column(Integer,primary_key=True,autoincrement=True)
    nome_db=Column(String(10))
    censimento=Column(Integer)
    versione=Column(Integer)
    ins_data=Column(DateTime)
    mod_data=Column(DateTime)
    ins_utente=Column(Integer)
    mod_utente=Column(Integer)
    MetaData.create_all()

    def __repr(self):
        return "dbmmas: {0}, censimento {1}, versione {2}".format(self.nome_db,self.censimento,self.versione)    

class funzione(Base):
    __tablename__="funzione"
    funzione_id=Column(Integer,primary_key=True,autoincrement=True)
    categoria=Column(String(10))
    nome=Column(String(20))
    def __repr__(self):
        return "funzione:{0},categoria:{1},id:{2} ".format(self.nome,self.categoria,self.funzione_id)

class profilo(Base):
    __tablename__="rel_utente_funzione" 
    utente_id=Column(Integer,primary_key=True)
    funzione_id=Column(Integer,primary_key=True)
    amministratore=Column(Integer)
    MetaData.create_all()

    def __repr(self):
        l=lambda x: "amministratore" if x==1 else "generico"
        return "profilo per utente_id:{0}, tipo: {1}, funzione_id: {2}".format(self.utente_id,l(self.amministratore),self.funzione_id)    

class aree(Base):
    __tablename__="rel_utente_zona" …
Run Code Online (Sandbox Code Playgroud)

python mysql sqlalchemy

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

在python中读取巨大的MySQL表的最快方法

我试图读取一个由数百万行组成的非常大的 MySQL 表。我使用过Pandas库和chunks. 请参阅下面的代码:

import pandas as pd
import numpy as np
import pymysql.cursors

connection = pymysql.connect(user='xxx', password='xxx', database='xxx', host='xxx')

try:
    with connection.cursor() as cursor:
        query = "SELECT * FROM example_table;"

        chunks=[]

        for chunk in pd.read_sql(query, connection, chunksize = 1000):
            chunks.append(chunk)
        #print(len(chunks))    
        result = pd.concat(chunks, ignore_index=True)
        #print(type(result))
        #print(result)

finally:
    print("Done!")

    connection.close()
Run Code Online (Sandbox Code Playgroud)

实际上,如果我限制要选择的行数,执行时间是可以接受的。但是如果只想选择最少的数据(例如100 万行),那么执行时间会急剧增加。

也许有更好/更快的方法从python中的关系数据库中选择数据?

python mysql numpy pandas

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

不支持 RSA 加密 - django mysql 和 docker 的 caching_sha2_password

我尝试使用 docker 连接 Mysql 与 django,但出现此错误

2061, 'RSA Encryption not supported - caching_sha2_password plugin was built with GnuTLS support'.
Run Code Online (Sandbox Code Playgroud)

我尝试更改用户并创建数据库

// create a user //

CREATE USER 'user'@'localhost' IDENTIFIED BY 'user';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' WITH GRANT OPTION;
CREATE USER 'user'@'%' IDENTIFIED BY 'user';
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%' WITH GRANT OPTION;

// create a database //

CREATE DATABASE user_db;
Run Code Online (Sandbox Code Playgroud)

但仍然是 sqme 错误消息

在设置.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'user_db',
        'USER': 'user', …
Run Code Online (Sandbox Code Playgroud)

mysql django docker

6
推荐指数
1
解决办法
9420
查看次数