Guest User

Untitled

a guest
Nov 30th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. # To connect to mariadb you would need to conda install the mysql-connector-python package
  2. import mysql.connector as mariadb
  3.  
  4. # Connect to the DB
  5. connection = mariadb.connect(
  6. user='USERNAME',
  7. password='PASSWORD',
  8. database='employees',
  9. host='HOSTNAME_OF_MARIADB'
  10. )
  11. cursor = connection.cursor()
  12.  
  13. # Execute the query
  14. cursor.execute("SELECT first_name, last_name FROM employees LIMIT 20")
  15.  
  16. # Loop through the results
  17. for first_name, last_name in cursor:
  18. print(f'First name: {first_name}, Last name: {last_name}')
Add Comment
Please, Sign In to add comment