Python交互Mysql
贴一段代码#!/bin/env pythonimport MySQLdbimport socketimport commandschoose=0user=raw_input('input username:')passwd=raw_input('input passwd:')def Main():s=socket.socket(AF_INET,SOCK_STREAM)
·
贴一段代码
#!/bin/env python
import MySQLdb
import socket
import commands
choose=0
user=raw_input('input username:')
passwd=raw_input('input passwd:')
def Main():
s=socket.socket(AF_INET,SOCK_STREAM)
s.bind('192.168.137.102',50005)
s.listen(2)
con,addr=s.accept()
commands.getoutput('systemctl start vsftpd')
data=(1024)
def Check():
print '''
Welcome FTP Server!
1. Get File
2. Put File
3. Show Files
4. Exit
'''
choose=raw_input('Input you choose:')
if choose not in range(1,6):
print "Input right choose(1~5)"
else:
Main()
def Mysql():
conn=MySQLdb.connect(host='localhost',user='root',passwd='westos',port=3306) ##首先通过MySQLdb模块,连接Mysql。
cur=conn.cursor() ##获取执行工具
cur.execute('select user,password from ftp.user') ##执行语句,返回受影响的行数
check=cur.fetchall() ##将上个执行语句的结果返回
for i in range(len(check)):
if user in check[i][0]:
if passwd == check[i][1]:
Check()
else:
print 'Password are wrong!'
else:
print "Username are wrong!"
conn.commit() ##将执行的结果保存至mysql
cur.close() ##从内存中释放
conn.close() ##从内存中释放
Mysql()
更多推荐
所有评论(0)