In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to operate the database in python, the content is concise and easy to understand, absolutely can make you shine, through the detailed introduction of this article I hope you can gain something.
Python3 connection mysql requires installation of the mysql module
1. Local installation: pycharm version 2019.3;python version 3.7.3;pymysql version 0.10.0;
2. Remote installation: Install centos7 system in virtual machine; install mysql version 5.7.23 in centos7 system;
Python interface to database
pymysql.Connect() Parameters
host(str): MySQL server address
port(int): MySQL server port number
user(str): username
passwd(str): Password
db(str): database name
charset(str): connection encoding
Connection object supported methods
cursor() creates and returns a cursor using this connection
commit() commits the current transaction
rollback() Rolls back the current transaction
close() Close the connection
Cursor object supported methods
execute(op) Executes a database query command
fetchone() gets the next line of the result set
fetchmany(size) Gets the next few lines of the result set
fetchall() fetches all rows in the result set
rowcount() Returns the number of data or affected rows
close() Closes the cursor object
PS: If you need Python learning materials, you can add the group below to find a free administrator to receive
Click on the group to get free Python learning materials
You can receive source code, project actual video, PDF files, etc. for free
#Create cursor conn = pymysql.connect(host='192.168.126.131', port=3306, user='root', password='123456', ) print(conn) cursor = conn.cursor() print(cursor) output: #Cursor object #If you want to know what properties and methods the cursor has, you can view everything defined by Cursor class in cursors.py file #View the version information of the connected database, using execute() and fetchall() methods defined by cursor class conn = pymysql.connect(host='192.168.126.131', port=3306, user='root', password='123456', ) cursor = conn.cursor() cursor.execute ("select version()") data = cursor.fetchall() print ("Mysql's version : %s " % data) output: Mysql's version : ('5.7.23',) # mysql version is 5.7.23 #Create databases and tables using sql statements or database tools navicat; CREATE DATABASE database_name; CREATE TABLE table_name (column_name column_type); The above content is how to operate the database in python. Have you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.