Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #100288
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-12-11 10:35 -0800 |
| References | <a1dc235b-b02e-40c6-adb7-9c280833372b@googlegroups.com> <mailman.102.1449697508.12405.python-list@python.org> |
| Message-ID | <7a25bebc-cace-4b53-9961-442e50fa9e2c@googlegroups.com> (permalink) |
| Subject | Re: How to connect the MYSQL database to Python program? |
| From | ICT Ezy <ictezy@gmail.com> |
On Wednesday, December 9, 2015 at 1:45:26 PM UTC-8, Mark Lawrence wrote:
> On 09/12/2015 17:51, ICT Ezy wrote:
> > Pl explain me how to connect the MYSQL database to Python program?
> >
>
> Use a search engine. Then run up an editor, write some code, run said
> code. If you then have problems state your OS, Python version and
> provide us with the full traceback.
>
> An alternative is to write a cheque for (say) GBP 1000 payable to the
> Python Software Foundation and if you're lucky somebody will do your
> homework for you.
>
> --
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
>
> Mark Lawrence
Now, I installed MYSQLDB and following code was done correctly.
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","TESTDB")
# prepare a cursor object using cursor() method
cursor = db.cursor()
# execute SQL query using execute() method.
cursor.execute("SELECT VERSION()")
# Fetch a single row using fetchone() method.
data = cursor.fetchone()
print "Database version : %s " % data
# disconnect from server
db.close()
Then done following SQL statements:
#!/usr/bin/python
import MySQLdb
# Open database connection
db = MySQLdb.connect("localhost","TESTDB" )
# prepare a cursor object using cursor() method
cursor = db.cursor()
Then not correctly work following SQL statements:
>>> import MySQLdb
>>> db = MySQLdb.connect("localhost","TESTDB" )
>>> cursor = db.cursor()
>>> sql = """CREATE TABLE EMPLOYEE (
FIRST_NAME CHAR(20) NOT NULL,
LAST_NAME CHAR(20),
AGE INT,
SEX CHAR(1),
INCOME FLOAT )"""
>>> cursor.execute(sql)
Traceback (most recent call last):
File "<pyshell#116>", line 1, in <module>
cursor.execute(sql)
File "C:\Python27\lib\site-packages\MySQLdb\cursors.py", line 205, in execute
self.errorhandler(self, exc, value)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1046, "Aucune base n'a \xe9t\xe9 s\xe9lectionn\xe9e")
>>>
How to solve the problems. pl explain me
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-09 09:51 -0800
Re: How to connect the MYSQL database to Python program? Chris Angelico <rosuav@gmail.com> - 2015-12-10 04:57 +1100
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:36 -0800
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:39 -0800
Re: How to connect the MYSQL database to Python program? Larry Martell <larry.martell@gmail.com> - 2015-12-11 13:51 -0500
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 11:00 -0800
Re: How to connect the MYSQL database to Python program? Igor Korot <ikorot01@gmail.com> - 2015-12-11 14:11 -0500
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 11:13 -0800
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 11:11 -0800
Re: How to connect the MYSQL database to Python program? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-09 21:42 +0000
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:35 -0800
Re: How to connect the MYSQL database to Python program? ICT Ezy <ictezy@gmail.com> - 2015-12-11 10:39 -0800
csiph-web