Created
April 23, 2021 02:55
-
-
Save erickythierry/2faec81d4c948016f2405e51b5fb376d to your computer and use it in GitHub Desktop.
This file contains hidden or 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='ip', user='root', password='senha', database='bd', port=32786) | |
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