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¡£
Ïà¹ØÎĵµ£º
1.show status
Threads_connected µ±Ç°µÄÁ¬½ÓÊý
Connections ÊÔͼÁ¬½Óµ½(²»¹ÜÊÇ·ñ³É¹¦)MySQL·þÎñÆ÷µÄÁ¬½ÓÊý¡£
Max_used_connections ·þÎñÆ÷Æô¶¯ºóÒѾͬʱʹÓõÄÁ¬½ÓµÄ×î´óÊýÁ¿¡£
2.set GLOBAL max_connections=Á¬½ÓÊý;
flush privilege ......
1¡¢²é¿´µ±Ç°ËùÓÐÁ¬½ÓµÄÏêϸ×ÊÁÏ:
mysqladmin -uroot -proot processlist
D:\MySQL\bin>mysqladmin -uroot -proot processlist
+-----+------+----------------+---------+---------+------+-------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+------+---------- ......
ÐÞÕýһϣºÎÒÔÚWindowsϵÄʵ¼Ê²Ù×÷ÈçÏÂ
1.¹Ø±ÕÕýÔÚÔËÐеÄMySQL¡£
2.´ò¿ªDOS´°¿Ú£¬×ªµ½mysql\binĿ¼¡£
3.ÊäÈëmysqld½â --skip-grant-tables»Ø³µ¡£Èç¹ûûÓгöÏÖÌáʾÐÅÏ¢£¬ÄǾͶÔÁË¡£
4.ÔÙ¿ªÒ»¸öDOS´°¿Ú£¨ÒòΪ¸Õ²ÅÄǸöDOS´°¿ÚÒѾ²»Äܶ¯ÁË£©£¬×ªµ½mysql\binĿ¼¡£
5.ÊäÈëmysql»Ø³µ£¬Èç¹û³É¹¦£¬½«³öÏÖMySQL ......
Ò»¡¢Îª´ÓÊý¾Ý¿âÉèÖø´ÖÆÕ˺Å
grant REPLICATION SLAVE on *.* To 'backup'@'%' identified by 'backuppwd'
flush privileges
¶þ¡¢µ¼³öÊý¾Ý
(1)Ö±½Ó¸´ÖÆÊý¾ÝÎļþĿ¼·½·¨
a. Í£Ö¹Êý¾Ý¿âдÊý¾Ý
flush tables with read lock
b.ÏÔʾ´ËʱmasterµÄ״̬
show master status
¼ÆÏ´ËʱÖ÷Êý¾Ý¿âµÄbinlogµ ......