mysql的一些操作

本机Windows:

1.启动mysql:需要管理员权限, cd C:\\users\\vesper\\mysql\\bin

net start mysql 

2.停止mysql: net stop mysql 

3.新建数据库: create database 数据库名; 

python操作mysql:

import MySQLdb

# 打开数据库连接
db = MySQLdb.connect("localhost", "root", "123456", "db1", charset='utf8' )

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

# 使用execute方法执行SQL语句
cursor.execute("SELECT VERSION()")

# 使用 fetchone() 方法获取一条数据
data = cursor.fetchone()

# 关闭数据库连接
db.close()

服务器:

1.启动: systemctl start mysqld.service 

2.查看运行状态: systemctl status mysqld.service 

 

posted @ 2019-12-10 16:49  glam  阅读(104)  评论(0)    收藏  举报