试图安装mysql-python.得到以下错误.已经安装了mysql和pythond.任何帮助将受到高度赞赏
[root@uu include]# easy_install mysql-python
Searching for mysql-python
Reading http://cheeseshop.python.org/pypi/mysql-python/
Couldn't find index page for 'mysql-python' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading http://cheeseshop.python.org/pypi/
Reading http://cheeseshop.python.org/pypi/MySQL-python/1.2.3c1
Reading http://sourceforge.net/projects/mysql-python
Best match: MySQL-python 1.2.3c1
Downloading http://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.3c1.tar.gz#md5=310dd856e439d070b59ece6dd7a0734d
Processing MySQL-python-1.2.3c1.tar.gz
Running MySQL-python-1.2.3c1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-toQ0nx/MySQL-python-1.2.3c1/egg-dist-tmp-OeN5eG
unable to execute gcc: No such file or directory
error: Setup script exited with error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud) 使用MySQLdb我连接到一个数据库,其中所有内容都以utf8编码存储.
如果我做
cursor.execute("SET NAMES utf8")
Run Code Online (Sandbox Code Playgroud)
并通过另一个语句从数据库中获取一些数据.这是否意味着,字符串在
cursor.execute("SELECT ...")
cursor.fetchall()
Run Code Online (Sandbox Code Playgroud)
将是unicode?或者我必须先把它们转过来
mystr.decode("utf8")
Run Code Online (Sandbox Code Playgroud)
unicode?
我想自己验证这个MySQL字符串是如何被光标翻译的:
cursor.execute("SELECT * from elements where id = %s", (element_id))
Run Code Online (Sandbox Code Playgroud)
有没有办法获取计算出的SQL字符串并将其打印出来,最好是在执行之前?(后者不是绝对必要的 - 我只是这样做,因为我正在学习Python,并希望确保我的SQL字符串被清理)
我创建了一个表“ table2”,并在运行代码时收到警告(表已存在)。我只想创建不存在的表。一些研究MySQL语法的网站在MySQL中提供了以下内容:如果不存在则创建表
我的代码:
cursor.execute('CREATE TABLE IF NOT EXISTS (2 INT)`table2`')
Run Code Online (Sandbox Code Playgroud)
提供以下警告:
_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 '(2 INT)`table2`' at line 1")
Run Code Online (Sandbox Code Playgroud)
我有数据库版本数据库版本:5.1.54-1ubuntu4汤姆
我想在我的程序中使用executemany来同时存储20条记录,下面是文档中的内容......
c.executemany(
"""INSERT INTO breakfast (name, spam, eggs, sausage, price)
VALUES (%s, %s, %s, %s, %s)""",
[
("Spam and Sausage Lover's Plate", 5, 1, 8, 7.95 ),
("Not So Much Spam Plate", 3, 2, 0, 3.95 ),
("Don't Wany ANY SPAM! Plate", 0, 4, 3, 5.95 )
] )
Run Code Online (Sandbox Code Playgroud)
但是,我在列表中有我的值,而不是使用我列表中的索引来执行上面的18个版本.
这是我下面的代码......
db = connect_to_db()
cursor = db.cursor()
sql = "INSERT INTO gkey (keyword, date, time, position) VALUES (%s, %s, %s, %s)"
params = [(str(keywords[0]), date, time, position[0])]
cursor.executemany(sql, params)
db.commit() …Run Code Online (Sandbox Code Playgroud) 我最近从10.6升级到Mac OS X 10.7.
我决定使用Python 2.7.
但是当我尝试安装MySQLdb模块来运行Django时,它失败了:
$ sudo pip install MySQL-python
Downloading/unpacking MySQL-python
[…]
Running setup.py install for MySQL-python
building '_mysql' extension
llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -mno-fused-madd -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -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/include -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.7-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute llvm-gcc-4.2: No such file or directory
error: command 'llvm-gcc-4.2' failed with exit status 1
Complete …Run Code Online (Sandbox Code Playgroud) 我有一个数据库,它有一个存储过程,我在我的python脚本中调用它.
直到昨天它没有问题.
但昨天我的数据库服务器出现问题并恢复了数据库.
现在我从同一个代码得到这个警告:
Warning: Incorrect string value: '\xD9\x88\xD8\xB2\xDB\x8C...' for column 'title' at row 1
Run Code Online (Sandbox Code Playgroud)
我检查了DB中的一些编码:
In INFORMATION_SCHEMA.COLUMNS:
+--------------+--------------------+
| COLUMN_NAME | CHARACTER_SET_NAME |
+--------------+--------------------+
| title | utf8 |
+--------------+--------------------+
Run Code Online (Sandbox Code Playgroud)
数据库排序规则:latin1_swedish_ci
表排序规则:utf8_general_ci
列排序规则:utf8_general_ci
服务器字符集:( UTF-8 Unicode (utf8)
全部与之前相同!!)
我正在使用这个连接:
self.con=mdb.connect(host=self.host, user=self.user, passwd=self.passwd, db=self.dbname,use_unicode=True, charset="utf8");
Run Code Online (Sandbox Code Playgroud)
和变量title是unicode.
我试过了:
utf8_general_ci为title列SET NAMES utf8 调用程序之前. 没有工作!!! :-(
我insert在一个带有Unicode内容的临时表上执行了一个查询,它没有那个警告!
问题是什么?
我怎样才能解决这个问题?
谢谢
我正在关注django教程,很多人都提出了这个问题,但我认为我的情况有点独特,因为安装python-mysql后,当我尝试做python manage.py syncdb时仍然会出现此错误,
我在virtualenv,因为我使用macports来管理我的python安装我创建了virtualenv
virtualenv code/vdjango --no-site-packages --python=/opt/local/bin/python
Run Code Online (Sandbox Code Playgroud)
在使用macports之前我安装了django py27-django,但是在创建了我的virtualenv之后,我认为我将django安装到virtualenv上更好,所以我使用了pip install django==1.5
根据django教程,我编辑了我的settings.py文件,然后执行python manage.py syncdb,最后出现以下错误:
[~/code/vdjango/newsite]$python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 453, in execute_from_command_line
utility.execute()
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 272, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/__init__.py", line 77, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/mac-pro/code/vdjango/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 8, in …Run Code Online (Sandbox Code Playgroud) 我试图通过python从mysql数据库访问数据,然后我尝试了
import MySQLdb
db = MySQLdb.connect(host = "127.0.0.1",
port = 3306,
user="Bishnu",
password = "Pulchowk",
db = "telecom_db")
cursor =db.cursor()
cursor.execute("select * from profile")
numrows = int(cursor.rowcount)
for x in range(numrows):
row = cursor.fetchone()
#if (row):
print row[0], row[1]
cursor.close()
db.cose()
Run Code Online (Sandbox Code Playgroud)
然后它显示错误
Traceback (most recent call last):
File "D:\Bishnu\BE\4th year\7th semester\Major Project I\Workspace\Bishnuji\default\first.py", line 43, in <module>
db = "telecom_db")
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: 'password' …Run Code Online (Sandbox Code Playgroud) 我正试图在Mac Os高山上运行
pip install MySQL-python
Run Code Online (Sandbox Code Playgroud)
但我得到了
error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
我已经尝试过关于这个主题的解决方案,但它没有用.
这是完整的错误消息
The directory '/Users/filipeferminiano/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/filipeferminiano/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the …Run Code Online (Sandbox Code Playgroud)