我知道这已被问过几次了,但经过几个小时的尝试,没有办法让这个工作.
我已经从dmg文件和MySQL-python-1.2.3安装了MySQL 32位.
我按照这个步骤操作,但是当我运行时python setup.py build,会出现这些错误:
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-fat-2.6/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -pipe -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql-5.5.12-osx10.6-x86/include -I/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6 -c _mysql.c -o build/temp.macosx-10.6-fat-2.6/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch i386
In file included from _mysql.c:36:
/usr/local/mysql-5.5.12-osx10.6-x86/include/my_config.h:326:1: warning: "SIZEOF_SIZE_T" redefined
In file included from /System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/Python.h:9,
from pymemcompat.h:10,
from _mysql.c:29:
/System/Library/Frameworks/Python.framework/Versions/2.6/include/python2.6/pymacconfig.h:39:1: warning: this is the location of the previous definition
In file included …Run Code Online (Sandbox Code Playgroud) 我试图安装MySQL-python包有以下错误:
cc1: error: unrecognized command line option "-arch"
cc1: error: unrecognized command line option "-Wno-long-double"
error: Setup script exited with error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
我正在使用Mac OSX version 10.6.8gcc
bash-3.2$ gcc --version
gcc (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题?
谢谢
我正在尝试设置Django以使用MySQL.当我输入时,我收到以下错误localhost/mysite
ExtractionError at /
Can't extract file(s) to egg cache
The following error occurred while trying to extract file(s) to the Python egg
cache:
[Errno 13] Permission denied: '/Library/WebServer/.python-eggs'
The Python egg cache directory is currently set to:
/Library/WebServer/.python-eggs
Perhaps your account does not have write access to this directory? You can
change the cache directory by setting the PYTHON_EGG_CACHE environment
variable to point to an accessible directory.
Run Code Online (Sandbox Code Playgroud)
从错误消息我知道我必须更改PYTHON_EGG_CACHE环境变量以指向Apache可以访问的目录.我尝试添加以下内容httpd.conf
SetEnv PYTHON_EGG_CACHE /var/www
<Directory /var/www>
Order deny,allow …Run Code Online (Sandbox Code Playgroud) 我在MySQLdb上使用xampp和python.我正在连接然后运行:
cursor.execute("INSERT INTO customer SET name='aaa'")
Run Code Online (Sandbox Code Playgroud)
不会引发任何错误,但没有向数据库添加任何行(与pypmyadmin一起检查).但是,该表正在递增其自动增量字段.
发生了什么,我该如何阻止它?
我试图从数据库中获取一个值pymysql.我目前的解决方案是3行代码.这是处理这个问题的最佳方法吗?
import pymysql
conn = pymysql.connect(host='localhost', user='root', passwd='')
conn.autocommit(True)
cur = conn.cursor()
memory = '100'
# I want to access one item from mySQL
cur.execute("""SELECT id FROM scada.sensors WHERE memory='{}'""".format(memory))
for x in cur.fetchall(): # only runs once
sensor_id=x[0]
Run Code Online (Sandbox Code Playgroud)
我需要这个for循环来访问内容cur.fetchall()吗?
我使用的是Python 3.2.3
我想在运行此代码时通过python.But简单地访问mysql数据库:
import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
port = "3306",
user="Bishnu",
passwd = "Pulchowk",
db = "student")
cursor =db.cursor()
cursor.execute("select * from basic_info")
numrows = int(cursor.rowcount)
for x in range(0,numrows):
row = cursor.fetchall()
print row[0],"-->",row[1]
db.cose()
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:
Traceback (most recent call last):
File "C:\Users\Bishnu\Desktop\database", line 6, in <module>
db = "student")
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: an integer is required
Run Code Online (Sandbox Code Playgroud)
那是什么TypeError:需要一个整数
为什么会出现这种问题 要运行此代码我有3个问题,但幸运的是这个论坛解决了我的两个问题,我认为它也将解决?
像许多人一样,我遇到了让mysql和python一起工作的问题.我的规格是:
OSX10.9.2带有python 2.7.2的Anaconda 1.9.1,虽然2.5和2.6似乎包含在MySQL 5.6.16中
我写了一个python脚本,我尝试导入MySQLdb,或PyMySQL然后MySQLdb,都没有工作.
我读了很多关于堆栈溢出的线程,结果我最终尝试了
$ export CFLAGS=-Qunused-arguments
$ export CPPFLAGS=-Qunused-arguments
$ pip install mysql-python
Run Code Online (Sandbox Code Playgroud)
结果如下.发出致命错误,可以在输出的底部看到.
下载/解压缩mysql-python下载MySQL-python-1.2.5.zip(108kB):108kB下载运行setup.py(路径:/ private/var/folders/lx/h7jq_qx92_j0n7plsjmr6wl40000gp/T/pip_build_vincent/mysql-python/setup. py)egg_info for package mysql-python
安装收集的软件包:mysql-python运行setup.py install for mysql-python构建'_mysql'扩展/ usr/bin/clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments - Dversion_info =(1,2,5,'final',1)-D_ version _ = 1.2.5 -I/usr/local/mysql/include -I/Users/vincentlaufer/anaconda/include/python2.7 -c _mysql .c -o build/temp.macosx-10.5-x86_64-2.7/_mysql.o -Os -g -fno-strict-aliasing -arch x86_64在_mysql.c中包含的文件中:29:/ Users/vincent/anaconda/include /python2.7/Python.h:33:10:致命错误:'stdio.h'文件未找到#include ^ 1错误生成.错误:命令'/ usr/bin/clang'失败,退出状态1完成输出命令/ Users/vincentlaufer/anaconda/bin/python -c"import setuptools,tokenize; file ='/ private/var/folders/lx/h7jq_qx92_j0n7plsjmr6wl40000gp/T/pip_build_vincent/mysql-python/setup.py'; exec(compile(getattr(tokenize,'open',open)(file).read().replace('\ r \n','\n' ),file,'exec'))"install --record /var/folders/lx/h7jq_qx92_j0n7plsjmr6wl40000gp/T/pip-6aqGYj-record/install-record.txt --single-version-external-managed --compile:running安装
运行构建 …
我试图通过python脚本运行MySQL查询并继续在我的SQL语法中出错,从我可以看到查询设置正确.有人可以给我第二眼吗?
conn = mysql.connector.connect(**config)
connect = conn.cursor()
query = u'INSERT INTO page_load_times (self, object_id, page_header, elapsed_time, date_run) ' \
'VALUES ({}, {}, {}, {}, {})'.format(self, self.object_id, self.page_header, t.interval, timestamp)
connect.execute(query)
conn.commit()
conn.close()
Run Code Online (Sandbox Code Playgroud)
我得到的错误如下:
ProgrammingError: 1064 (42000): 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 '13:56:17.491000)' at line 1
Run Code Online (Sandbox Code Playgroud) 我在下面的代码中删除了日期列值为current_date的表中的所有行。
db = MySQLdb.connect("localhost",'root','XXXX','XXXX')
cur = db.cursor()
query = "delete from RealTimeData where date = current_date()"
cur.execute(query)
db.commit()
Run Code Online (Sandbox Code Playgroud)
现在,我怎么知道我的查询从表中删除了多少行?我尝试过fetchone()回来None
我最近升级到Mac OS Mojave,现在无法安装MySQL-Python:
pip install MySQL-Python
...
clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-2.7/_mysql.o -L/usr/local/opt/mysql-client/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-x86_64-2.7/_mysql.so
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪显示未找到“ ssl”库。我不确定这是什么意思,因为我已经安装了最新的XCode和OpenSSL。任何建议表示赞赏。
mysql-python ×10
python ×8
mysql ×6
macos ×2
python-2.7 ×2
anaconda ×1
delete-row ×1
django ×1
macos-mojave ×1
phpmyadmin ×1
pip ×1
python-3.x ×1
sql ×1
xampp ×1