python向数据库mysql,sqlite3插入外部变量
2018-01-31 21:10
489 查看
一,若要插入外部非字符串变量可以用
data = 55
cur.execute("insert into book(name,price) values('html',{})".format(data))
cur.commit()二,若要插入外部字符串变量时要用
bookname = 'Python'
cur.execute("insert into book(name,price) values('{}',55)".format(bookname))
cur.commit()三,对于mysql,若要插入中文字符要用语句
db = pymysql.connect(host = '127.0.0.1',user = 'root',passwd = '123456',db = 'test1',charset = 'utf8')四,创建mysql时若要使用中文字符时得使用
sql ="CREATE TABLE book(name varchar(20) NOT NULL,price integer )ENGINE=InnoDB DEFAULT CHARSET=utf8"
#执行sql语句
cursor.execute(sql)
db.close()
data = 55
cur.execute("insert into book(name,price) values('html',{})".format(data))
cur.commit()二,若要插入外部字符串变量时要用
bookname = 'Python'
cur.execute("insert into book(name,price) values('{}',55)".format(bookname))
cur.commit()三,对于mysql,若要插入中文字符要用语句
db = pymysql.connect(host = '127.0.0.1',user = 'root',passwd = '123456',db = 'test1',charset = 'utf8')四,创建mysql时若要使用中文字符时得使用
sql ="CREATE TABLE book(name varchar(20) NOT NULL,price integer )ENGINE=InnoDB DEFAULT CHARSET=utf8"
#执行sql语句
cursor.execute(sql)
db.close()
相关文章推荐
- Java 链接Mysql 数据库时使用变量插入数据方法
- python插入数据库Mysql 关键字段
- MySQL-Python 库插入数据到数据库中看不到数据
- 修改(python) mysql 数据库 使其可以支持插入中文
- python连接sqlite(mysql)数据库以及sqlite数据库基础操作
- Python数据库访问之SQLite3、Mysql
- c#几种数据库的大数据批量插入(SqlServer、Oracle、SQLite和MySql)
- Python利用dict构造数据库(mysql)的插入语句
- python 数据库操作 SQLite、MySQL 摘录
- 基于python sqlite3将KDD-99数据集插入数据库中
- Python数据库访问之SQLite3、Mysql
- Python 数据库连接(sqlite, mysql, oracle, postgresql, sql server)
- python对MySQL进行数据的插入、更新和删除之后需要commit,数据库才会真的有数据操作。(待日后更新)
- Python创建插入数据库MySQL
- Python数据库相关(SQLServer/sqlite/MySQL/access)
- python 试题:以mysql或者sqlite为例,请用代码给出简洁且完整的数据库操作示例。
- Python学习笔记 使用数据库SQlite Mysql
- 如何将Emoj表情插入mysql5.6数据库__python+mysqldb
- python数据库操作-MySQL,SQLite
- 怎样将Emoj表情插入mysql5.6数据库__python+mysqldb