<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          使用mysql.connector 向mysql表寫入數(shù)據(jù)

          共 832字,需瀏覽 2分鐘

           ·

          2021-11-12 21:12

          mysql.connector 是mysql官方提供的驅(qū)動器,可使用pip進行安裝

          pip install mysql-connector


          創(chuàng)建一張mysql表

          create table city(
          id int NOT NULL AUTO_INCREMENT,
          `name` varchar(50) NOT NULL,
          PRIMARY KEY (`id`)
          )ENGINE=InnoDB DEFAULT CHARSET=utf8;


          接下來,向這張表里寫入數(shù)據(jù)

          import mysql.connector

          mydb = mysql.connector.connect(
          host="your ip", # 數(shù)據(jù)庫主機地址
          user="username", # 數(shù)據(jù)庫用戶名
          passwd="password", # 數(shù)據(jù)庫密碼
          port=6606,
          database='flink_db'
          )

          sqls = [
          "insert into city(name)values('北京')",
          "insert into city(name)values('上海')",
          "insert into city(name)values('廣州')",
          "insert into city(name)values('深圳')",
          ]

          mycursor = mydb.cursor()

          for sql in sqls:
          mycursor.execute(sql)

          mydb.commit()


          insert 語句會向表里新增數(shù)據(jù),數(shù)據(jù)庫有變動,必須執(zhí)行commit,否則不會生效


          瀏覽 69
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  婷婷中文网 | 中文字幕+乱码+中文字幕17c | 成人青娱乐 | 欧美性爱在线视频 | 日韩高清一级 |