Skip to content

Instantly share code, notes, and snippets.

@erickythierry
Created April 23, 2021 02:55
Show Gist options
  • Save erickythierry/2faec81d4c948016f2405e51b5fb376d to your computer and use it in GitHub Desktop.
Save erickythierry/2faec81d4c948016f2405e51b5fb376d to your computer and use it in GitHub Desktop.
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