Get the App
SLTechnology News&Howtos  ›  Database  › 

How to successfully connect to a MySQL database using pyMySQL

Shulou Source: shulou.com Published: 2022-06-01 19:47:41 10月07日 Update

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.

Tags: Success data database specialty industry expertise subject book content reality document news terminology board module knowledge article information question Tiandu Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei macOS NVidia MySQL Microsoft