How to connect the MYSQL database to Python program?

Larry Martell larry.martell at gmail.com
Fri Dec 11 13:51:46 EST 2015


On Fri, Dec 11, 2015 at 1:36 PM, ICT Ezy <ictezy at gmail.com> wrote:
> On Wednesday, December 9, 2015 at 9:58:02 AM UTC-8, Chris Angelico wrote:
>> On Thu, Dec 10, 2015 at 4:51 AM, ICT Ezy <ictezy at gmail.com> wrote:
>> > Pl explain me how to connect the MYSQL database to Python program?
>>
>> You start by looking for a module that lets you do that. You can use
>> your favourite web search engine, or go directly to PyPI.
>>
>> Then you learn how to use that module, including learning SQL if you
>> don't already know it.
>>
>> ChrisA
>
> Now, I installed MYSQLDB and following code was done correctly.
>
> #!/usr/bin/python
>
> import MySQLdb
>
> # Open database connection
> db = MySQLdb.connect("localhost","TESTDB")

The connect should look like this:

db= MySQLdb.connect(host, user, passwd, db)

Or to be clearer:

db= MySQLdb.connect(host="localhost", user="user", passwd="password",
db="TESTDB")



More information about the Python-list mailing list