您的位置:首页 > 编程语言 > Python开发

MySql 关闭和重启 及Python对MySQL的简单操作

2016-10-11 14:29 483 查看
Windows下:

关闭:net stop mysql

启动: net start mysql

RedHat下:

启动:# service mysqld start

停止:# service mysqld stop

重启:# service mysqld restart

Python对MySQL的简单操作

# -*- coding: UTF-8 -*-
import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("localhost","user","pwd","test" )

# 使用cursor()方法获取操作游标
cursor = db.cursor()

# 使用execute方法执行SQL语句
cursor.execute("SHOW TABLES;")

# 使用 fetchall() 方法获取所有表。
tables = cursor.fetchall()

for table in tables:
print "table  %s " % table

# 关闭数据库连接
db.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: