Training my english !!!
Hello, my name is Lucas. I be writing this artigle for sharing an code for connect python with database MySQL.
For connecting python in database mysql, we require install an library ( mysql-connector ). For install this library, you can write in your concolse the command(using PIP):
pip install mysql-connector-python
- With library instaling, we can initialize the create code for connection. In your VSCode, create an file with name "app.py";
- In your file "app.py" import the library ( mysql-connector ) writing the this line:
import mysql.connector
- In your file "app.py" write the code with data the connectio MySQL
mydb = mysql.connector.connect(
host='',
user='',
password='',
database=''
)
-
host
: the host of connection in database MySQL; -
user
: username of connection in database; -
password
: password of connection in database; -
database
: name of your database
For finality the code, we have to write the line of conection:
con = mydb.cursor()
Your code should look like this:
import mysql.connector
mydb = mysql.connector.connect(
host='',
user='',
password='',
database=''
)
con = mydb.cursor()
Top comments (0)