Connecting to a Database
Import the mysql class and create an instance by passing your connection credentials.
The connection is opened immediately.
from easymysql.mysql import mysql
db = mysql(host, user, password, database)
Parameters
| Parameter | Type | Description |
|---|---|---|
host | str | MySQL server hostname or IP address |
user | str | Database user |
password | str | Database password |
database | str | Name of the database to use |
Example
from easymysql.mysql import mysql
db = mysql('localhost', 'root', 'secret', 'shop')
After this line, db is ready to use. All subsequent operations — insert, select,
update, delete — are called as methods on this object.