单表查询:select * from 表 where 条件 group by 分组 having 过滤 order by 排序 limit n;语法:select distinct 字段1,字段2... from 表名 where 条件 group by 组名 having 筛选 order by 排序 limit 限制条数找到表:from拿着where指定的约束条件,去文件/表中取出一条条记录将取出的一条条记录进行分组group by,如果没有group by,则整体作为一组执行select(去重):select * from 表名;将分组的结果进行having过滤将结果按...
1.系统必须安装MySQL-python软件,否则python没有连接的模块(在Linux系统)yum install MySQL-python2.安装mysql数据库yum install mysql-server mysql[root@AY140528120357495c4bZ ~]# /etc/init.d/mysqld restartStopping mysqld: [ OK ]Starting mysqld: [ OK ][root@AY140528120357495c4bZ ~]#3.在mysql中创建数据库和表[root@AY1405...
我的python版本( 2.7 )需要安装python mysql驱动sudo pip install MySQL-python如果报错,找不到mysql_config:sudo ln -s /usr/local/mysql57/bin/mysql_config /usr/local/bin/mysql_config这里自己根据实际情况,建立一个软连接,驱动就能够找到mysql_config,因为我mysql装在/usr/local/mysql57下面如果报错,找不到libmysqlclient.so.20,同样建立一个对应的软连接( 请根据自己电脑的实际情况在相应的目录建立软链接 )sudo ln ...
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/6/15 22:46
# @Author : Kwan
# @File : insert_db.py
# @Software: PyCharmimport sqlite3
import random
import datetime# conn = sqlite3.connect('local.db')
#
# c = conn.cursor()
#
# c.execute("insert into system_cfg values(?,?,?)",(2,'test2',1))
#
# conn.commit()
#
# conn.close()def make_date():
# def make_card_n...
一、Mysql基本操作1、创建test数据库2、新建一张表3、向msg表中插入数据4、对表中的数据进行增删改查 二、Python操作mysqlimport MySQLdbconn = MySQLdb.connect(host="127.0.0.1",user="root",\passwd="123456",db="test",\port=3306,charset="utf8")cur=conn.cursor()n=cur.execute(sql,param)cur.close()conn.commit()connrollback()conn.close() 三、Python 操作mysql-插入数据1、直接插入一条数据cur.execute("insert into m...
对于Python操作MySQL主要使用两种方式:原生模块 pymsqlORM框架 SQLAchemypymsqlpymsql是Python中操作MySQL的模块,其使用方法和MySQLdb几乎相同。下载安装pip3 install pymysql
使用操作1、执行SQL#!/usr/bin/env python
# -*- coding:utf-8 -*-
import pymysql# 创建连接
conn = pymysql.connect(host=‘127.0.0.1‘, port=3306, user=‘root‘, passwd=‘123‘, db=‘t1‘)
# 创建游标
cursor = conn.cursor()# 执行SQL,并返回...
在这些 URL 中,hostname 表示 MySQL 服务所在的主机,可以是本地主机(localhost),也可以是远程服务器。数据库服务器上可以托管多个数据库,因此 database 表示要使用的数据库名。如果数据库需要进行认证,username 和 password 表示数据库用户密令。 原文:http://www.cnblogs.com/bell1991/p/7070582.html
import pymysql# 获取一个数据库连接,注意如果是UTF-8类型的,需要制定数据库
db = pymysql.connect(host="127.0.0.1",user="root",passwd="123456",db="mysql",charset=‘utf8‘ )
# 使用 cursor()方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute()方法执行 SQL 查询
cursor.execute("SELECT user,host,password from user")
# 使用 fetchall()方法获取所有行.
data = cursor.fetchall()
print(data)
cursor.clo...
增删改from pymysql import *def main():# 创建Connection连接conn = connect(host=‘localhost‘,port=3306,database=‘jing_dong‘,user=‘root‘,password=‘mysql‘,charset=‘utf8‘)# 获得Cursor对象cs1 = conn.cursor()# 执行insert语句,并返回受影响的行数:添加一条数据 # 增加count = cs1.execute(‘insert into goods_cates(name) values("硬盘")‘)#打印受影响的行数print(count)count = cs1.execute(‘insert into g...
Python爬取房天下某城市数据随着互联网时代的兴起,技术日新月异,掌握一门新技术对职业发展有着很深远的意义,做的第一个demo,以后会在爬虫和数据分析方便做更深的研究,本人不会做详细的文档,有哪里不足的地方,希望大牛们指点讲解。废话不多说,上代码。你需要的技能:(1)对前端知识熟悉会调试浏览器(2)熟练python基础知识,对一些常用的库熟练掌握(3)掌握一般关系型数据库import requests as req
import time
import p...
1#!/usr/bin/env python 2# -*- coding:utf-8 -*- 3import MySQLdb4 5 conn = MySQLdb.connect(host=‘192.168.1.101‘,user=‘root‘,passwd=‘123‘,db=‘host‘)6 cur = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)7 reCout = cur.execute(‘select ip,name from host,user where user.name = "alex" and user.id=host.id‘)8 nRet = cur.fetchall()9conn.commit()
10cur.close()
11conn.close()
12print reCout
13pr...
在centos7环境中常规安装python3的话无法支持sqlite3和ssl,所以在安装pytho3是需要带上sqlite3库和ssl库:下载编译安装sqlite3:# wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate# ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"# make && make instal...
目录一, 数据库的安装和连接二, 创建表操作三, 操作数据四, SQL注入问题一, 数据库的安装和连接PyMySQL的安装:pip install PyMySQLpython连接数据库:import pymysqldb = pymysql.connect("数据库ip","用户","密码","数据库" ) # 打开数据库连接
cursor.execute("SELECT VERSION()") # 使用 execute() 方法执行 SQL 查询
data = cursor.fetchone() # 使用 fetchone() 方法获取单条...
First download, build and install sqlite3 with a --prefix. Then build python with same prefix , it will find sqlite installation and will build _sqlite3 module.$ mkdir -
p
~
/applications/
src
$ cd
~
/applications/
src
$ wget http
:
//www.sqlite.org/sqlite-autoconf-3070900.tar.gz$ tar xvvf sqlite
-
autoconf
-
3070900.tar
.
gz
$ cd sqlite
-
autoconf
-
3070900$
./
configure
--
prefix
=~/
applica...
脚本内容#! /usr/local/python3/bin/pythonimport os
import psycopg2
import timedb_host = "172.16.101.54"
db_port = 5432
db_user = "dbadmin"
db_password = "agm43gadsg"
db_default = "postgres"
backup_path = "/usr/local/pgsql/dba/exp"
backup_day = time.strftime("%Y%m%d")
databases = []# check backup path if exists.def check_backup_path():ifnot os.path.exists(backup_path):os.mkdir(backup_path)# get all ...