Common functions of python database operations (create table insert count instance 1, obtain MYSQL version)
The code is as follows:
#-*-Coding: UTF-8 -*-# Install mysql db for pythonImport MySQLdb as mdbCon = NoneTry:# Method for connecting to mysql: connect ('IP', 'user', 'password', 'dbname ')Con = mdb. connect ('localhost', 'root ','Root', 'test ');# All queries are run on the cursor module connected to con.Cur = con. cursor ()# Execute a queryCur.exe cute ("select version ()")# Obtain the r
performed only when the obtained cursor is obtained.Cur = con. cursor ()# Create a data table writers (id, name)Cur.exe cute ("create table if not exists \Writers (Id int primary key AUTO_INCREMENT, Name VARCHAR (25 ))")# Five data entries are inserted belowCur.exe cute ("insert into Writers (Name) VALUES ('Jack London ')")Cur.exe cute ("insert into
Instance 1. Obtain the MYSQL version
Copy codeThe Code is as follows:#-*-Coding: UTF-8 -*-# Install mysql db for pythonImport MySQLdb as mdbCon = NoneTry:# Method for connecting to mysql: connect ('IP', 'user', 'Password', 'dbname ')Con = mdb. connect ('localhost', 'root ','Root', 'test ');# All queries are run on the cursor module connected to con.Cur = con. cursor ()# Execute a queryCur.exe cute ("select version ()")# Obtain the result of the previous query, which is a single resultData = cur.
, you must clarify the responsibilities in the preparation of technical documents. These methods include:
Add the name of the author and related personnel to the technical document. Some companies may have regulations to prohibit the appearance of employee names, but the practice of including the name of the author and related persons in the technical documents can promote communication between these internal employees. For external document users, such as user guides for commercial spot softwa
Example 1, get the MySQL version
Copy Code code as follows:
#-*-Coding:utf-8-*-
#安装MYSQL DB for Python
Import MySQLdb as MDB
con = None
Try
#连接mysql的方法: Connect (' IP ', ' user ', ' password ', ' dbname ')
con = mdb.connect (' localhost ', ' root ',
' Root ', ' test ');
#所有的查询, is running on a module cursor that connects con.
cur = con.cursor ()
#执行一个查询
Cur.execute ("SELECT VERSION ()")
#取得上个查询的结果, is a single result
data = Cur.fetchone ()
Print "Data
MYSQLDB module's provided API method to manipulate the database. It is also the MySQL version number that gets the installation of the current host. Create a new table Next, we create a table from the MySQLdb module and populate it with some data. The implementation code is as follows: #!/usr/bin/python
#-*-Coding:utf-8-*-
ImportMySQLdb asMySQL conn = Mysql.connect (' 127.0.0.1 ',' TestUser ',' test123 ',' TestDB '); withConn:cur = Conn.cursor () Cur.execute ("DROP TABLE IF EXISTS
Spreadsheet
Time Limit: 1000MS
Memory Limit: 10000K
Total Submissions: 617
Accepted: 290
DescriptionIn 1979, Dan Bricklin and Bob Frankston wrote VisiCalc, the first spreadsheet application. It became a huge success and, at that time, is the killer application for the Apple II computers. Today, spreadsheets is found on the most desktop computers.The idea behind
interface
You will then see a very strange view of Excel, which looks like a shell of an Excel application (pictured below). There are no workbooks, no spreadsheets,-one is bare Excel.
Of course, this is definitely not available, but it's a prerequisite for creating a workbook, which is the container that holds the workbook. Now we need to add a workbook to the application. To do this, you need to use the Add method of the Workbook object
Tags: localhost python version except cursorThis article describes how Python operates MySQL, executes SQL statements, obtains result sets, iterates through result sets, obtains a field, gets the name of a table column, inserts a picture into a database, executes various code instances such as a transaction, and describes it in detail. Example 1, getting the MySQL version#!/usr/bin/env python
import mysqldb as MDB
try:
con=mdb.connect (' localhost ', ' root ', ' 123 ', ' Test ') #连The MySQL meth
Ps:mysqldb only available for python2.xPython3 does not support MYSQLDB and is replaced by PymysqlRun the report: Importerror:no module named ' MySQLdb 'ImportPymysql as PMQ#Connect (ip.user,password,dbname)con = Pmq.connect ('localhost','Root','123456','python_test')#Manipulating CursorsCur =con.cursor ()#Build TableCur.execute ("CREATE TABLE IF not EXISTS writers (Id INT PRIMARY KEY auto_increment,name VARCHAR )")#Insert Data OneCur.execute ("INSERT
deleted ). Save the config file after modification.
7. Submit all updates in cvsroot to the server, and our settings will take effect. The command is as follows:
CD cvsroot CVS add-M "" Admin CVS commit-M ""
However, before submission, you may want to change the cvsroot owner from the original administrator to cvsadmin. Use the command CVS chown to do this. After the cvsroot directory is submitted, the verification mode changes immediately and the cvsadmin takes effect at the same time. In this
Like hardware, computer software is constantly evolving. The following is an example of an electronic form, briefly explaining the evolution of the software development process.Speaking of spreadsheets, what many people think of? The answer is office Excel. Office Excel has become the most commonly used Office tool software for enterprises or individuals, especially in the daily management of enterprises, statistics, is a large number of applications
Implementing agile does not require a certain or recommended use of tools. Ideally, looking at the requirements on the index card, the development can be done through the command line. However, a number of tools have emerged in recent years that have contributed to the successful completion of agile development. Migan and Gaia recently conducted a survey to try to draw on the use of tools by Agile development teams.According to two, one of the reasons they did the survey was to assess whether ag
Document directory
Overview
Busy developers 'Guide to features
Because of some requirements, you need to use Java to save some data into excel. It is good to hear from friends that the Apache poi Project (hereinafter referred to as POI)
Poi provides a series of interfaces for reading and generating Microsoft's Ole 2 compound document format, which is Excel, Word ..
Because you only want to read and generate an Excel file, you can directly jump
Http://poi.apache.org/hssf/index.html super s
Everyone is very convenient to use précis-writers domain name such as yourname.yeah.net, a lot of people think: if I can make my server can also implement précis-writers domain name is good. Actually, it's not complicated. After reading this article, you can also do a précis-writers domain Name System.
The key technology of the précis-
business problems, we need to quickly make judgments based on the discussion, the basis for making judgments is often the grasp of the system, understanding of the technology, and self-confidence. On the other hand, in fact, many questions do not necessarily have absolute right or wrong, but after we make judgments, we can stop endless discussions.
3. enrich content
At the end of the discussion stage, content enrichment is just physical activity. As long as the
Because the project database is to be transferred to MySQL, it took me an hour to understand the usage of Python-mysql. The following is a summary: #-*-coding: UTF-8-*-import mysqldb as mdbimport sys # Set con to global connection con = MDB. connect ('localhost', 'root', '', 'test'); with Con: # obtain the linked cursor, only the obtained cursor, we can perform various operations cur = con. cursor () # create a data table writers (ID, name) cur.exe cu
result: Database version:5.5.25
instance 2, creating a table and inserting data
Mainly in the cursor above execute Execute method to proceed, see Source code:
The code is as follows
Copy Code
#-*-Coding:utf-8-*-# from Www.crazyant.net Summary finishingImport MySQLdb as MDBImport Sys #将con设定为全局连接con = mdb.connect (' localhost ', ' root ', ' root ', ' test '); With Con: #获取连接的cursor, we can do all kinds of things only if we get cursor.cur = con.cursor ()
object of constant repair in the process of pursuing modernization. No language, like Chinese, has undergone such a major change over the past one hundred years. Since the late Qing Dynasty followed the Japanese Meiji Restoration's "" movement, the Chinese language experienced the Wusi Vernacular Movement and simplified the simplified scheme of the world language, Chinese characters, popular languages, and post-liberation traditional Chinese characters, in the face of the national crisis of sur
If your own server can also implement the précis-writers domain name is good. Actually, it's not complicated. You can also make a précis-writers domain Name System.
The key technology of the précis-writers domain Name system is to implement Web page redirection (redirctory). In essence, the précis-writers domain Name
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.