python如何连接MySQL数据库
#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#=========================================================================
"""
***** This is a MySQL test *****
select:
conn=Connection()
conn.select_db('test')
cur=conn.cursor()
cur.execute('select * from user')
cur.scroll(0)
row1=cur.fetchone()
row1[0]
row1[1]
row1[2]
insert:
cur.execute('insert into user (name,passwd) values('benyur','12345')')
cur.insert_id()
update:
cur.execute('update user set passwd='123456' where name='benyur'')
delete:
cur.execute('delete from user where id=2')
**********************************
"""
from MySQLdb import *
def conn():
conn=Connection()
conn.select_db('test')
cur=conn.cursor()
cur.execute('select * from user')
cur.scroll(0)
row1=cur.fetchone()
row1[0]
row1[1]
row1[2]
def usage():
print __doc__
if __name__=='__main__':
usage()
MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/
下载解压缩后放到%Python_HOME%Libsite-packages目录中,python会自动找到此包。
MySQLdb基本上是MySQL C API的Python版,遵循Python Database API Specification v2.0。
相关文档:
这个代码是基于python3.0写的,有许多不完善的地方,请自已修改。
# coding: utf-8
from tkinter import *
root = Tk()
root.title("python3.0查询")
#root.minsize(800,600)
#填充无用空间
Label(root).grid(ipady=5)
#11面板
class Frame11:
def __init__(self, root): # ......
1、查看当前所有连接的详细资料:
mysqladmin -uroot -proot processlist
D:\MySQL\bin>mysqladmin -uroot -proot processlist
+-----+------+----------------+---------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+---------- ......
《mysql 与 php 基础教程》
1. 文本函数
函数
用法
用途
CONCAT()
CONCAT(x,y,...)
创建形如xy的新字符串
CONCAT_WS()
CONCAT_WS(separator,column1,column2,...)
分隔符将插入所列出的每个列之间
LENGTH()
LENGTH(column)
返回列中存储的字符串的长度
LEFT()
LEFT(colum,x)
从列的值中返回最左边的x ......
1016错误:文件无法打开,使用后台修复或者使用phpmyadmin进行修复。
1044错误:数据库用户权限不足,请联系空间商解决
1045错误:数据库服务器/数据库用户名/数据库名/数据库密码错误,请联系空间商检查帐户。
1054错误:程序文件跟数据库有冲突,请使用正确的程序文件上传上去覆盖。
1146错误:数据表缺失,请恢 ......