Path: csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Igor Korot Newsgroups: comp.lang.python Subject: Re: How to connect the MYSQL database to Python program? Date: Fri, 11 Dec 2015 14:11:04 -0500 Lines: 62 Message-ID: References: <9261e7b4-48ad-45f2-ba65-066177d21f6b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de RinOiN1qrkWDJJUCandFfAW96n4bIHcvcmNsAWsA90Gw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.05; 'friday,': 0.07; 'wednesday,': 0.07; 'cc:addr:python-list': 0.09; 'subject:How': 0.09; '__init__': 0.09; 'python': 0.10; 'python.': 0.11; 'thu,': 0.15; 'db)': 0.16; 'generated,': 0.16; 'program?': 0.16; 'pypi.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'statement.': 0.16; 'subject:program': 0.16; 'wrote:': 0.16; 'module,': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '"",': 0.22; 'correctly.': 0.22; 'trying': 0.22; 'am,': 0.23; 'code.': 0.23; 'dec': 0.23; 'this:': 0.23; 'import': 0.24; '(most': 0.24; 'header:In-Reply-To:1': 0.24; 'module': 0.25; 'installed': 0.26; 'chris': 0.26; 'skip:m 30': 0.27; 'error': 0.27; 'fri,': 0.27; 'skip:# 10': 0.27; 'message- id:@mail.gmail.com': 0.27; '**kwargs)': 0.29; 'connection': 0.30; 'that.': 0.30; 'url:mailman': 0.30; 'code': 0.30; 'december': 0.32; 'url:python': 0.33; 'lets': 0.33; 'traceback': 0.33; 'open': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'file': 0.34; 'received:google.com': 0.35; 'done': 0.35; 'skip:" 50': 0.35; 'but': 0.36; 'skip:i 20': 0.36; 'should': 0.36; 'there': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:?': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'received:209.85.213': 0.37; 'received:209': 0.38; 'anything': 0.38; 'skip:p 20': 0.38; 'thank': 0.38; 'hi,': 0.38; 'does': 0.39; 'subject:the': 0.39; 'url:mail': 0.40; 'some': 0.40; 'your': 0.60; 'skip:u 10': 0.61; 'email addr:gmail.com': 0.62; 'more': 0.63; 'you.': 0.64; 'account': 0.66; 'user,': 0.67; '81,': 0.84; 'chrisa': 0.84; 'ict': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=MlksuuTGHbysuVOKq7H8dG/BJbzZcaXPv7P88Flrjes=; b=lnxuysByRbDMoG41L37B6I1OFwdo4kFm1sYShyddtAFAnmPdaFzriYwKP3lEE2l5/v 9RiJgZe4CGGM24Q2k2UJ4xtdQM7+irEJKL+D7KwOX3M/B5HxtWDkZYDWK2yj/fgGzWXM YbTm6Ujr3wPGaZl0z9Zs+xb54+2PUF3l9lVYLMlSuMApXRD9+dMoZ+mvlbZltqyE96SP PJ5H40jL1iv7N6IHOMOz8PtkZbL2fRRuGDoHtHtvYe8cxQpNpRpzO4saxNDNXXefJMJB M5D6Xqze5qNqTyGRN9vp4+Thya0ngp025+SKIcATpchxYpCQBqgQYFeTzSquvNIjrSkR AZOA== X-Received: by 10.31.54.133 with SMTP id d127mr320123vka.126.1449861064956; Fri, 11 Dec 2015 11:11:04 -0800 (PST) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100298 Hi, On Fri, Dec 11, 2015 at 2:00 PM, ICT Ezy wrote: > On Friday, December 11, 2015 at 10:52:49 AM UTC-8, Larry....@gmail.com wrote: >> On Fri, Dec 11, 2015 at 1:36 PM, ICT Ezy 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 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") > > if there was error generated, i remove password and user > >>>> db= MySQLdb.connect(host="localhost", user="testuser", passwd="test123",db="TESTDB") > > Traceback (most recent call last): > File "", line 1, in > db= MySQLdb.connect(host="localhost", user="testuser", passwd="test123",db="TESTDB") > File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect > return Connection(*args, **kwargs) > File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 193, in __init__ > super(Connection, self).__init__(*args, **kwargs2) > OperationalError: (1045, "Acc\xe8s refus\xe9 pour l'utilisateur: 'testuser'@'@localhost' (mot de passe: OUI)") >>>> Is the account testuser exist? Does it have a password "test123"? But more imp[ortantly - this does not have anything to do with Python. Start by trying to connect from mySQL and try to execute some insert/update/delete statement. Then when you succeed, start writing python code. Thank you. > pl check it > -- > https://mail.python.org/mailman/listinfo/python-list