Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to successfully connect to a MySQL database using pyMySQL

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly tells you how to successfully connect to the MySQL database using pyMySQL. You can check the relevant professional terms on the Internet or find some related books to supplement them. We will not dabble here, so let's go straight to the topic. I hope this article on how to successfully connect to the MySQL database using pyMySQL can bring you some practical help.

Download the pyMySQL module package

[root@kurol ~] # python36-m pip install pyMySQLCollecting pyMySQL Downloading PyMySQL-0.7.11-py2.py3-none-any.whl (78kB) 100% | # # | 81kB 8.9kB/s Installing collected packages: pyMySQLSuccessfully installed pyMySQL-0.7.11

Create a py file

[root@kurol ~] # touch mysqltest.py [root@kurol ~] # vim mysqltest.python3-*-coding: UTF-8-*-# import os,sysimport pymysqltry: conn = pymysql.connect (host='localhost',user='root',passwd='') Db='db_student') except Exception as e: print (e) sys.exit () cursor = conn.cursor () sql = "select * from stu_inf" cursor.execute (sql) data = cursor.fetchall () if data: for x in data: print (x [0], x [1], x [2], x [3], x [4], x [5]) cursor.close () conn.close ()

Use pyMySQL how to successfully connect to the MySQL database to tell you here, for other related issues you want to know can continue to pay attention to our industry information. Our section will capture some industry news and professional knowledge to share with you every day.

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report