mysql

作者: 六诗人 | 来源:发表于2018-04-07 20:48 被阅读0次

    Connection对象

    .用于建立与数据库的链接

    .创建对象:调用connect()方法

    conn=connect(参数列表)

    .参数host:连接的mysql主机,如果本机是'localhost'

    .参数port:连接的mysql主机的端口,默认是3306

    .参数db:数据库的名称

    .参数user:连接的用户名

    .参数password:连接的密码

    .参数charset:通信采用的编码方式,默认是'gb2312',要求与数据库创建时指定的编码一致,否则中文会乱码

    对象的属性

    rowcount只读属性,表示最近一次execute()执行后受影响的行数

    connection获得当前连接对象

    增加数据

    count=cs1.execute("insert into students(sname)values('张三')")

    修改数据

    conut=cs1.execute("update students set sname='李四' where id=6")

    删除数据

    conte=cs1.execute("delete from students where id=6")

    查询数据

    查询一行数据:cur.execute('select * from students (表名) where (条件) id=7')  result=cur.fetchone()

    查询多行数据: cur.execute('select * from students (表名) ') result=cur.fetchall()

    导入数据库模块

    import pymysql

    连接数据库

    db = pymysql.connect("MySQL地址","账号","密码","d1")

    创建数据库表

    使用预处理语句创建表

    sql = """CREATE TABLE STUDENTS ()

    数据库的插入操作

    #SQL插入语句

    sql = """INSERT INTO EMPLOYEE ()

    相关文章

      网友评论

        本文标题:mysql

        本文链接:https://www.haomeiwen.com/subject/xscuhftx.html