Skip to content

Instantly share code, notes, and snippets.

@mayararysia
Last active October 6, 2023 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mayararysia/49fb1e17a9b29aa3385f147e27ec5f2b to your computer and use it in GitHub Desktop.
Save mayararysia/49fb1e17a9b29aa3385f147e27ec5f2b to your computer and use it in GitHub Desktop.
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