Last active
October 6, 2023 12:32
-
-
Save mayararysia/49fb1e17a9b29aa3385f147e27ec5f2b to your computer and use it in GitHub Desktop.
File that connects to the MySQL database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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