安装MySQL
安装mysql很简单,这里不多赘述了,网上很多教程。
mysql下载地址
图形界面工具(gitee)
图形界面工具(github)
视频教程
文章
开启mysql
win+R
开启:net start mysql
关闭:net stop mysql
mysql一些简单操作
显示当前数据库 show databases;

使用一个数据库 use test;

重命名
– 修改表名
rename table old_table to new_table;
– 或者
alter table old_table rename as new_table;
– 修改列名称
alter table table_name
change column old_name new_name varchar(255);
– 修改字段类型
alter table table_name
modify column column_name varchar(255) default ‘’ COMMENT ‘注释’;
插入数据
insert into score (name,score) values(‘小明’,’80’);
删除
drop table tb;
drop 是直接将表格删除,无法找回。例如删除 user 表:
drop table user;
truncate (table) tb;
truncate 是删除表中所有数据,但不能与where一起使用;
TRUNCATE TABLE user;
delete from tb (where);
delete 也是删除表中数据,但可以与where连用,删除特定行;
— 删除表中所有数据
delete from user;
— 删除指定行
delete from user where username =’Tom’;
delete from score where score = 80;
查询
select * from score where name like ‘%刘%’;
python 连接mysql
import pymysql
from pymysql.cursors import DictCursor
# 创建数据库连接 localhost等效于127.0.0.1
conn = pymysql.connect(host="127.0.0.1",port=3306,user="root",passwd="123456",db="test",charset="utf8")
# 建立游标,指定游标类型,返回字典
cur = conn.cursor(DictCursor)
# 操作语句,只查询前两行
try:
sql = """select download_url from urls where file_name like '%cat%' limit 20;"""
# 执行sql语句
cur.execute(sql)
# 获取查询的所有结果
res = cur.fetchall()
# 打印结果
# print(res)
with open("xxx.md","a+" )as f:
for x in res:
# print(x['download_url'])
f.write(f"\n")
except:
print("操作失败")
finally:
# 关闭游标
cur.close()
# 关闭连接
conn.close()
PS :以后一些操作会记录。
23333