This is a simple program on connecting your python with database and then working with simple SQL query. If you are using Pycharm IDE then you need to first install mysql connector
for your python program to work with MySQL database. For this you can go to File->Settings->Project:(you will see your project name)->Python Interpreter. Then click +
sign in the top right and search for mysql-connector. Then you can click that and install the package. Then you are good to go.
I had a database name called userdb
in MySQL Workbench and student
is the table of that database. I am printing whatever is inside that table. This query will show that.
import mysql.connector
mydb=mysql.connector.connect(host="localhost", user="root", passwd="12345", database="userdb")
mycursor=mydb.cursor()
mycursor.execute("select * from student")
for i in mycursor:
print(i)
As you run this program, the following output will be seen.
Is your MySQL Database getting corrupt somehow? Then you can go for Cigati MySQL Database Repair Tool to Recover the Corrupt MySQL Database Without Losing Any Data. This tool can support the recovery of MySQL Database from both InnoDB & MyISAM tables. Using this tool, you can easily restore Tables, Queries, Reports, Forms, & indexes into an accessible form of access database.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
If you work with MySQL database you can test dotconnect mysql.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit