Advertisement
teslariu

db_mysql

May 29th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. """
  5. pip install pymysql
  6. python -m pip install pymysql
  7. """
  8. import pymysql
  9.  
  10. # como conectarse a una base de datos
  11. conn = pymysql.connect(
  12.     host = "localhost",
  13.     user = "nombre_del_usuario",
  14.     passwd = "contraseña",
  15.     db = "nombre_base_datos"
  16.     )
  17.    
  18. # como agregar datos (usando el ejemplo de la tabla personas)
  19. for nombre, edad in personas:
  20.     cursor.execute("INSERT INTO personas VALUES (%s, %s)",(nombre, edad))
  21.    
  22. """
  23. excepciones: pymysql.err.InternalError  sintaxis
  24.              pymysql.ProgrammingError
  25.  
  26. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement