World's Best AI Learning Platform with profoundly Demanding Certification Programs
Designed by IITians, only for AI Learners.
Internship Partner

In Association with
In collaboration with



Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
New to InsideAIML? Create an account
Employer? Create an account
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
Enter your email below and we will send a message to reset your password
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Designed by IITians, only for AI Learners.
Internship Partner
In Association with
In collaboration with
By providing your contact details, you agree to our Terms of Use & Privacy Policy.
Already have an account? Sign In
Download our e-book of Introduction To Python
4.5 (1,292 Ratings)
589 Learners
Vijay Parekh
2 years ago
import mysql.connector as mysql
test= mysql.connect(
host="localhost",
user="username",
password="password"
)
print(test)
>python demo_mysql_connection.py
<mysql.connector.connection.MySQLConnection object ar 0x016645F0>
import mysql.connector as mysql
test= mysql.connect(
host="localhost",
user="username",
password="password"
)
mycursor = test.cursor()
mycursor.execute("CREATE DATABASE mydatabase")
import mysql.connector as mysql
test= mysql.connect(
host="localhost",
user="yourusername",
password="yourpassword"
)
mycursor = test.cursor()
mycursor.execute("SHOW DATABASES")
for x in mycursor:
print(x)
('information_scheme',)
('mydatabase',)
('performance_schema',)
('sys',)