Python3----对远程windows server 2003服务器的mysql数据库中指定库创建数据表

Python3—-对远程windows server 2003服务器的mysql数据库中指定库创建数据表

1、参考数据库的数据表的格式

这里写图片描述

2、Python代码:

# -*- coding: utf-8 -*-
"""
Created on Fri Jun 22 20:00:02 2018

@author: Administrator
"""
import os
import sqlite3
import operator
import pymysql

def connect_mysql():
    db_config = {
        'host':'192.168.16.115',#远程windows server 2003数据库地址
        'port':3306,
        'user':'root',
        'password':'root',
        'db':'chrome_history',#需要连接的数据库test
        'charset':'utf8mb4'#编码
    }
    try:
        cms = pymysql.connect(**db_config)
        cur = cms.cursor()#获取一个游标
        #对chrome_history库创建表urls数据
        cur.execute("CREATE TABLE urls (id VARCHAR(10), url VARCHAR(500), title VARCHAR(150), visit_count VARCHAR(20), type VARCHAR(2), last_visit_time VARCHAR(20), hidden VARCHAR(2));")
        cur.execute('flush privileges;')#必须实时更新数据
        cur.execute('select * from urls;')#查询urls数据表中所有数据
        data = cur.fetchall()
        for d in data:#打印查询的member数据表的数据
                print('id: '+str(d[0])+'\t'+'url: '+str(d[1])+'\t'+'title: '+str(d[2])+'\t'+'visit_count: '+str(d[3])+'\t'+'type: '+str(d[4])+'\t'+'last_visit_time: '+str(d[5])+'\t'+'hidden: '+str(d[6]))
        cur.close()
    except Exception as e:
        print(e)

db = connect_mysql()
3、脚本运行后:

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

徐为波

看着给就好了,学习写作有点累!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值