Skip to content

Instantly share code, notes, and snippets.

@mayararysia
Last active Sep 4, 2019
Embed
What would you like to do?
File that connects to the MySQL database
import mysql.connector
from mysql.connector import errorcode
try:
db_connection = mysql.connector.connect(host='localhost', user='root', password='', database='bd')
print("Database connection made!")
except mysql.connector.Error as error:
if error.errno == errorcode.ER_BAD_DB_ERROR:
print("Database doesn't exist")
elif error.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("User name or password is wrong")
else:
print(error)
else:
db_connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment