fromsqlalchemyimportcreate_enginefromsqlalchemy.ext.declarativeimportdeclarative_basefromsqlalchemyimportColumn,Integer,Stringfromsqlalchemy.ormimportsessionmakerfromsqlalchemyimportfuncengine=create_
1.基本用法importpymysql#建立连接conn=pymysql.connect(host='localhost',port=3306,user='root',password='123456',db='mydb')#创建游标cursor=conn.cursor()#执行sqleffect_row=cursor.execute("select*fromstudent")#查询第一行#row
1.innerjoin(内连接,或等值连接)select*fromtable1innerjointable2ontable1.column1=table2.column2;2.leftjoin(左连接)select*fromtable1leftjointable2ontable1.column1=table2.column2;3.rightjoin(右连接)select*fromtable1rig
1.创建外键,关联两个表createtablescore(idintnotnullauto_increment,subjectchar(32)notnull,stu_idintnotnull,primarykey(id),keyfk_stu_key(stu_id),constraintfk_stu_keyforeignkey(stu_id)referencesstudent(stu_id));
1.创建数据表createtabletable_name(idintnotnullauto_increment,namecharnotnull,ageintnotnull,register_datedate,primarykey(id);)2.插入数据(增)insertintotable_name(name,age,register_date)values("mxm",23,"2018-07-13
1.连接数据库mysql-uroot-p1234562.展示数据库showdatabases;3.打开/切换数据库usemysql;4.展示数据表showtables;5.展示表结构descuser6.查询数据select*fromuser7.创建数据库createdatabasechartsetutf-8;
Copyright © 2005-2024 51CTO.COM 版权所有 京ICP证060544号