Advertisement
teslariu

pymysql

Sep 6th, 2023
1,292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Script que se conecta a una base MySQL
  4. # instalar previamente pymysql: pip install pymysql
  5.  
  6. import pymysql
  7.  
  8. conn = pymysql.connect(
  9.         host = "localhost",
  10.         user = "root",
  11.         port = 3306,
  12.         passwd = "",
  13.         db = "comercioit"
  14.         )
  15.        
  16. cursor = conn.cursor()
  17.  
  18.  
  19. cursor.execute("SELECT * FROM productos")
  20. datos = cursor.fetchall()
  21. print(datos)
  22.  
  23. # cerrar la base
  24. conn.close()
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement