Kivy SQLalchemy 和 Android,没有名为 MySQLdb 的模块

Kivy SQLalchemy and Android, No module named MySQLdb

我正在为 android 构建一个应用程序,我需要与 Mysql 数据库进行交互。我在从 android 配置访问时遇到了一些问题,但在我的 linux 安装中却没有。

我已经在我的 android apk 上成功导入了 SQLAlchemy 的配方,但是当我 运行 应用程序槽 logcat 我看到错误:

NO module named MySQLdb

所以我尝试在 buildozer 中添加 MySQLdb 的配方,它说:

No matching distribution found for MySQLdb

这是调用mysql部分的代码部分:

import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy import MetaData, Column, Table, ForeignKey
from sqlalchemy import Integer, String
from sqlalchemy.sql import select

def check_sql_list(_id, string):
    cur = engine.connect()
    res = cur.execute("SELECT * FROM tbl_user")
    for x in res.fetchall():
        if x[_id] == string: return True
    cur.close()

def create_user(name,e_mail,psw):
    if check_sql_list(1,name):
        print 'Select another username.'
    elif check_sql_list(2,e_mail):
        print 'Your E-Mail have already an account.'
    else:
        connection = engine.raw_connection()
        try:
            cursor = connection.cursor()
            cursor.callproc("sp_createUser",[name, e_mail, psw])
            results = list(cursor.fetchall())
            for a in cursor.fetchall():
                print a
            print results
            cursor.close
            connection.commit()
        finally:
            connection.close()
            print 'Account registered succesfully.'

ip = 'localhost'
databs = 'mydb'
user = 'guest'
psw = 'password'
porta = '3306'

engine = create_engine('mysql://' + user + ':' + psw + '@' + ip + ':' + porta + '/' + databs)
create_user('user001','mail@001.com','password')

如何在不需要 MySQLdb 配方的情况下连接到我的数据库?或者我在哪里可以找到那个食谱?

我回答我自己的问题,希望有人会觉得它有用。

我找到了解决方法,用作拨号器 mysql+mysql 连接器,例如:

engine = create_engine('mysql+mysqlconnector://user00:psw@localhost:3306/database')

并在 buildozer.spec 中添加配方要求:

requirements = kivy,sqlalchemy,mysql_connector

kivy -m pip install mysql-connector

比:

import mysql.connector

为我工作:)