我使用以下查询:
select count(*) from Table1 where CurrentDateTime>'2012-05-28 15:34:02.403504' and Error not in ('Timeout','Connection Error');
Run Code Online (Sandbox Code Playgroud)
令人惊讶的是,此语句不包含具有错误值为NULL的行.我的意图是仅将具有错误值的行过滤为"超时"(或)"连接错误".我需要提供一个附加条件(OR错误为NULL)来检索正确的结果.
为什么MYSQL使用NULL值过滤掉结果?我认为IN关键字将返回一个布尔结果(1/0),现在我明白一些MYSQL关键字不返回布尔值,它也可能返回NULL ....但为什么它将NULL视为特殊?
我在Mac OSX Mountain Lion上构建MySQLdb时遇到了麻烦.从OSX Lion升级到OSX Mountain Lion后,我也下载并安装了Xcode 4.4.然后,我转到Xcode的Preference> Downloads并安装了命令行工具.
我已经下载了MySQL-python ver.1.2.3来自http://sourceforge.net/projects/mysql-python/
我跑的时候
python setup.py build
Run Code Online (Sandbox Code Playgroud)
我得到以下消息:
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.6-intel-2.7/MySQLdb
running build_ext
building '_mysql' extension
gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -g -O2 -DNDEBUG -g -O3 -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/local/mysql/include -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.6-intel-2.7/_mysql.o -Os -g -fno-common -fno-strict-aliasing -arch x86_64
unable to execute gcc-4.2: No such file or directory
error: command 'gcc-4.2' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
但是,gcc存在.我跑的时候
gcc
Run Code Online (Sandbox Code Playgroud)
我明白了
i686-apple-darwin11-llvm-gcc-4.2: no input files
Run Code Online (Sandbox Code Playgroud)
下面是我发现的类似问题,但它的解决方案正是我已经做过的,对我来说不起作用.
我正在使用所有软件的最新版本(Django,Python,virtualenv,MySQLdb),我无法使用它.当我从virtualenv外部的python提示符中运行"import MySQLdb"时,它可以工作,里面写着"ImportError:没有名为MySQLdb的模块".
我正在努力学习Python和Linux Web开发.我知道使用SQLLite是最简单的,但是我想学习如何开发比我在.NET中可以做的更大规模的应用程序.我已经阅读了Google上的每篇博文和StackOverflow上的每篇帖子,他们都建议我运行"sudo pip install mysql-python",但它只是说"要求已经满足:/ usr/lib/pymodules /中的mysql-python" python2.7"
任何帮助,将不胜感激!我被困在这里并且不想放弃,只是回到微软技术上这样做,因为我甚至无法启动和运行基本开发环境.
我创建一个连接到mysql的python程序.
我需要检查一个表是否包含数字1,以表明它已成功连接,这是我的代码到目前为止:
xcnx.execute('CREATE TABLE settings(status INT(1) NOT NULL)')
xcnx.execute('INSERT INTO settings(status) VALUES(1)')
cnx.commit()
sqlq = "SELECT * FROM settings WHERE status = '1'"
xcnx.execute(sqlq)
results = xcnx.fetchall()
if results =='1':
print 'yep its connected'
else:
print 'nope not connected'
Run Code Online (Sandbox Code Playgroud)
我错过了什么?我是一个sql noob,谢谢你们.
每次我重启MySQL服务器
bitnami@xxx:/$ sudo opt/bitnami/ctlscript.sh start server
Run Code Online (Sandbox Code Playgroud)
WWarning: World-writable config file '/opt/bitnami/mysql/my.cnf' is ignored
Warning: World-writable config file '/opt/bitnami/mysql/my.cnf' is ignored
121120 12:30:18 mysqld_safe Logging to '/opt/bitnami/mysql/data/mysqld.log'.
121120 12:30:18 mysqld_safe Starting mysqld daemon with databases from /opt/bitnami/mysql/data
121120 12:30:20 mysqld_safe mysqld from pid file /opt/bitnami/mysql/data/ip-10-136-14-170.pid ended
/opt/bitnami/mysql/scripts/ctl.sh : mysql could not be started
Run Code Online (Sandbox Code Playgroud)
服务器响应以下错误:
(2002,"无法通过socket连接到本地MySQL服务器'/tmp/mysql.sock'(2)")
请告诉我我必须做些什么来解决这个问题.
这个错误破坏了我在Mac 10.7.5上的python-mysql安装.这是步骤
安装配置
1) sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
2) Edit the setup_posix.py and change the following mysql_config.path = "mysql_config" to mysql_config.path = "/usr/local/mysql/bin/mysql_config"
3) sudo python setup.py build
Run Code Online (Sandbox Code Playgroud)这是构建的堆栈跟踪
running build
running build_py
copying MySQLdb/release.py -> build/lib.macosx-10.7-intel-2.7/MySQLdb
running build_ext
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,4,'final',1) -D__version__=1.2.4 -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 -Wno-null-conversion -Os …Run Code Online (Sandbox Code Playgroud) 我有一个Python程序,它在后台运行数周,并且每隔一段时间就进行一次数据库查询.为此,我使用ORM peewee(版本2.2.1).我MySQL用作后端.
最近我遇到了访问数据库的反复出现的问题,通常是在运行程序几天之后.引起的错误peewee是
peewee.OperationalError: (2006, 'MySQL server has gone away')
Run Code Online (Sandbox Code Playgroud)
追溯是深入的peewee.我在这里发布,但由于我的virtualenv文件名太长,我缩短它们:
File ".../local/lib/python2.7/site-packages/peewee.py", line 2910, in save
ret_pk = self.insert(**field_dict).execute()
File ".../local/lib/python2.7/site-packages/peewee.py", line 2068, in execute
return self.database.last_insert_id(self._execute(), self.model_class)
File ".../local/lib/python2.7/site-packages/peewee.py", line 1698, in _execute
return self.database.execute_sql(sql, params, self.require_commit)
File ".../local/lib/python2.7/site-packages/peewee.py", line 2232, in execute_sql
self.commit()
File ".../local/lib/python2.7/site-packages/peewee.py", line 2104, in __exit__
reraise(new_type, new_type(*exc_value.args), traceback)
File ".../local/lib/python2.7/site-packages/peewee.py", line 2223, in execute_sql
res = cursor.execute(sql, params or ())
File ".../local/lib/python2.7/site-packages/MySQLdb/cursors.py", line 205, …Run Code Online (Sandbox Code Playgroud) 我想得到一个表的列名,但其中有数百万个数据.所以我不能用:
cursor.execute("SELECT * FROM table_name")
print cursor.description
Run Code Online (Sandbox Code Playgroud)
在sqlite3中,我这样做
crs.execute("PRAGMA table_info(%s)" %(tablename[0]))
for info in crs:
print info
Run Code Online (Sandbox Code Playgroud)
但这不适用于python mysqldb.谁知道怎么做?
在with语句中创建的变量的范围在with块之外(请参阅:使用with-statement在with-block之外可用的变量定义?).但是当我运行以下代码时:
class Foo:
def __init__(self):
print "__int__() called."
def __del__(self):
print "__del__() called."
def __enter__(self):
print "__enter__() called."
return "returned_test_str"
def __exit__(self, exc, value, tb):
print "__exit__() called."
def close(self):
print "close() called."
def test(self):
print "test() called."
if __name__ == "__main__":
with Foo() as foo:
print "with block begin???"
print "with block end???"
print "foo:", foo # line 1
print "-------- Testing MySQLdb -----------------------"
with MySQLdb.Connect(host="xxxx", port=0, user="xxx", passwd="xxx", db="test") as my_curs2:
print …Run Code Online (Sandbox Code Playgroud) 我是python的新手,我正在尝试涉及一些MySql的django框架,并在尝试执行pip install mysqlclientcmd消息时遇到了此错误。
Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient
Running setup.py install for mysqlclient ... error
Complete output from command c:\users\ronanl~1\envs\py1\scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\RONANL~1\\AppData\\Local\\Temp\\pip-install-pkbqy3t3\\mysqlclient\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\RONANL~1\AppData\Local\Temp\pip-record-moxwf7lu\install-record.txt --single-version-externally-managed --compile --install-headers c:\users\ronanl~1\envs\py1\include\site\python3.7\mysqlclient:
running install
running build
running build_py
creating build
creating build\lib.win32-3.7
copying _mysql_exceptions.py -> build\lib.win32-3.7
creating build\lib.win32-3.7\MySQLdb
copying MySQLdb\__init__.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\compat.py -> build\lib.win32-3.7\MySQLdb
copying MySQLdb\connections.py -> build\lib.win32-3.7\MySQLdb …Run Code Online (Sandbox Code Playgroud) mysql-python ×10
mysql ×7
python ×7
amazon-ec2 ×1
bitnami ×1
django ×1
gcc ×1
macos ×1
orm ×1
peewee ×1
python-2.7 ×1
python-3.x ×1
virtualenv ×1