mysql+用户批量导出,python批量导出导入MySQL用户的方法
詳細(xì)出處參考:http://www.jb51.net/article/43294.htm
#!/usr/bin/env python
#-*-encoding:utf-8-*-
#-------------------------
#name: mysql_usr_dump.py
#Purpose: 批量導(dǎo)出用戶
#Author: huangchengdu
#--------------------------
import MySQLdb
def
get_data(conn):
query = 'select user,host from mysql.user order by user'
cursor = conn.cursor()
cursor.execute(query)
lines = cursor.fetchall()
return lines
def
output_data(conn,rows):
for user,host in rows:
query ="show grants for '%s'@'%s'" %(user,host)
cursor = conn.cursor()
cursor.execute(query)
show_pri = cursor.fetchall()
for grants_command in show_pri:
print ''.join(grants_command)+';'
print ''
if __name__=='__main__':
conn =MySQLdb.connect
(host='localhost','user='root',passwd='huang',db='mysql',port=3306,charset='utf-8')
rows = get_data(conn)
output_data(conn,rows)
總結(jié)
以上是生活随笔為你收集整理的mysql+用户批量导出,python批量导出导入MySQL用户的方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php流量中转,中转Webshell绕过
- 下一篇: php 浏览商品记录,php浏览历史记录