how to connect to mysql database in python
import mysql.connector
cnx = mysql.connector.connect(user='scott', password='password',
host='127.0.0.1',
database='employees')
cnx.close()
how to connect to mysql database in python
import mysql.connector
cnx = mysql.connector.connect(user='scott', password='password',
host='127.0.0.1',
database='employees')
cnx.close()
connect python to mysql
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
port = 8888, #for Mamp users
database='whatever db you want'
)
print(mydb)
mysql python connector
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword"
)
print(mydb)
mysql connector python
import mysql.connector
try:
connection = mysql.connector.connect(host='localhost',database='dbname',user='root',password='xxxxx')
# print(dir(connection))
# print(connection.connection_id)
if connection.is_connected():
db_Info = connection.get_server_info()
print("Connected to MySQL Server version ", db_Info)
cursor = connection.cursor()
cursor.execute("select database();")
record = cursor.fetchone()
print("You're connected to database: ", record)
except Error as e:
print("except")
print("Error while connecting to MySQL", e)
finally:
if (connection.is_connected()):
cursor.close()
connection.close()
print("MySQL connection is closed")
mysql connection python
from sqlalchemy import types, create_engine
import pymysql
try:
conn = create_engine('mysql+pymysql://user:pass@IP/database_name')
print("MySQL Connection Sucessfull!!!!!!!!!!!")
except Exception as err:
print("MySQL Connection Failed !!!!!!!!!!!")
print(err)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us