Ok, I've been browsing through the MySQLdb docs, and I *think* I know
the kind of code I need to write (connect, cursor, manipulate data,
commmit, etc. -- although I probably need to get more familiar with
actual SQL commands too), but here's my problem: I don't know where
these scripts are supposed to be executed, or how they are supposed to
'find' the database.
Really, I have the same question for two different scenarios: accessing
and working with a database that is stored locally on my PC, and the
same with a DB that is on my web server space. I figure I already know
the host, username, password and database name (in fact, all these
things are spelled out as far as my web DB is concerned; I assume my
host name for the local DB is my computer's name).
But my question is, can these DB scripts be executed anywhere, and they
will find the DB based on the connect() parameters? Or do I need to do
something special with them? It seems like a similar problem to when you
don't have your PYTHONPATH variable set up properly. I've tried some DB
stuff, but it doesn't seem to work.
If more information is needed, I will try my local DB when I get home
later. As for the web DB, I figure there's probably more issues involved
that I'm not aware of, since web programming is still new to me.
So without actually giving you some code and tracebacks, is there any
general advice about how to set up these scripts? Also, is there any
better documentation than this: http://sourceforge.net/docman/displa...group_id=22307
It doesn't seem too thorough, and it also doesn't cover actual SQL
queries that you'd have to pass to the query method. Maybe I will just
have to find that information in a MySQL tutorial.
Thanks. 17 1912
On Fri, 12 May 2006 14:01:51 +0000, John Salerno wrote: Ok, I've been browsing through the MySQLdb docs, and I *think* I know the kind of code I need to write (connect, cursor, manipulate data, commmit, etc. -- although I probably need to get more familiar with actual SQL commands too), but here's my problem: I don't know where these scripts are supposed to be executed, or how they are supposed to 'find' the database.
I'm kind of a noob myself, but I'll see if I can't offer some useful info
anyhow.
When you issue your MySQLdb.connect, that determines where the database
actions occur. If you specify "host='localhost'", then you are trying to
connect to your local machine. If you specify "host='db.smurgle.net'",
you're trying to connect to my home db server. You can specify the
hostname in any format that your local machine understands; for example,
if you are on a Linux box, and your /etc/hosts file contains a line like:
10.0.0.10 myDBserver
then you can use "host='myDBserver'".
This isn't so much a web programming issue as it is using MySQL's network
interface. MySQL by default uses port 3306 (I think) to handle database
connections over the network.
But my question is, can these DB scripts be executed anywhere, and they will find the DB based on the connect() parameters? Or do I need to do something special with them? It seems like a similar problem to when you don't have your PYTHONPATH variable set up properly. I've tried some DB stuff, but it doesn't seem to work.
Your scripts that make connections can be executed from anywhere that:
1) knows how to communicate with the specified database server, and
2) has some sort of MySQL client available.
So without actually giving you some code and tracebacks, is there any general advice about how to set up these scripts? Also, is there any better documentation than this: http://sourceforge.net/docman/displa...group_id=22307
If you are having problems, by all means post some code.
It doesn't seem too thorough, and it also doesn't cover actual SQL queries that you'd have to pass to the query method. Maybe I will just have to find that information in a MySQL tutorial.
A couple of good MySQL tutorials would most likely be a big help. The
standard docs (the ones you pointed out) are not of a great deal of help
if you're totally new to SQL. You might want to do a Google search. This
will lead you to pages like: http://www.kitebird.com/articles/pydbapi.html http://www.devshed.com/c/a/Python/My...y-With-Python/
and the like.
Dan
CatDude wrote: On Fri, 12 May 2006 14:01:51 +0000, John Salerno wrote:
Ok, I've been browsing through the MySQLdb docs, and I *think* I know the kind of code I need to write (connect, cursor, manipulate data, commmit, etc. -- although I probably need to get more familiar with actual SQL commands too), but here's my problem: I don't know where these scripts are supposed to be executed, or how they are supposed to 'find' the database.
I'm kind of a noob myself, but I'll see if I can't offer some useful info anyhow.
Thanks very much for the info! I'll give the 'localhost' a try again and
see if I was creating problems elsewhere, perhaps with the commands
themselves. (All I know for sure is that I created a MySQL database and
filled it with baseball statistics, so I know *that* exists, at least!
But it was created from the MySQL prompt itself, not using Python.)
I'll also read over those links, they seem like the kind of thing I need
to really get going with it. :)
John Salerno wrote: If more information is needed, I will try my local DB when I get home later.
Ok, here we go:
import MySQLdb
db = MySQLdb.connect(host='localhost',
user='johnjsal',
passwd='seinfeld',
db='bbdatabank')
cursor = db.cursor()
cursor.execute('SELECT * FROM Master')
data = cursor.fetchall()
cursor.close()
db.close()
print data
And the output:
Traceback (most recent call last):
File "C:\Python24\myscripts\db_test.py", line 6, in -toplevel-
db='bbdatabank')
File "C:\Python24\lib\site-packages\MySQLdb\__init__.py", line 66, in
Connect
return Connection(*args, **kwargs)
File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line
134, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'localhost'
(10061)")
The situation is this: I installed MySQL 5.0, created a database called
bbdatabank using the MySQL prompt. Within the database there is a table
called Master, which I'm testing on. Obviously something is happening
with the connect method. Perhaps I'm doing something wrong. Is there a
way to get more info about what's happening?
Thanks.
John Salerno wrote: Traceback (most recent call last): File "C:\Python24\myscripts\db_test.py", line 6, in -toplevel- db='bbdatabank') File "C:\Python24\lib\site-packages\MySQLdb\__init__.py", line 66, in Connect return Connection(*args, **kwargs) File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 134, in __init__ super(Connection, self).__init__(*args, **kwargs2) OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
Latest development: I turned off my firewall and it worked. :)
John,
I had nothing but trouble connecting to my Access and MySql dbs until I
started using mxODBC. Search on it in this group, and you'll find the
links that were given to me and that I've shared with others. It works
like a charm.
If you come up short, I'll send you the links. I can't dig them up
right now. Back in an hour or so.
rick
John Salerno wrote: Ok, I've been browsing through the MySQLdb docs, and I *think* I know the kind of code I need to write (connect, cursor, manipulate data, commmit, etc. -- although I probably need to get more familiar with actual SQL commands too), but here's my problem: I don't know where
[...] So without actually giving you some code and tracebacks, is there any general advice about how to set up these scripts? Also, is there any better documentation than this: http://sourceforge.net/docman/displa...group_id=22307
It doesn't seem too thorough, and it also doesn't cover actual SQL queries that you'd have to pass to the query method. Maybe I will just have to find that information in a MySQL tutorial.
Thanks.
Interactive SQL tutorial: http://www.sqlcourse.com/ ; http://sqlcourse2.com/
Indirectly helpful maybe: http://initd.org/tracker/pysqlite/wiki/basicintro
HTH
Gerard
John,
Yep, different module. I'll watch the thread. Perhaps once you get
connected, we should make a mini-HOWTO for XP users while it's fresh in
your mind, because this question seems to come up a lot, and beginners
would probably appreciate a short howto that would perhaps detail how
to set up either mysqldb, mxodbc, or both on XP and get Python talking
to MySQL.
I think no matter which you choose, you will benefit from downloading
the mysql connector and adding your mysql db to datasources on XP. Then
you can access the db just by using the name you gave it in the
datasources panel, e.g. driv="bbdatabank"
rick
>> driv="bbdatabank"
Oops, sorry, I meant,
driv='DSN=bbdatabank'
rick
Dennis Lee Bieber wrote: On Fri, 12 May 2006 21:00:49 -0400, John Salerno <jo******@NOSPAMgmail.com> declaimed the following in comp.lang.python:
Latest development: I turned off my firewall and it worked. :)
Next step -- figure out what rule you need to define to the firewall to permit it to work...
Yeah, that's actually what I'm trying to do now. I'm not sure how to
define it, but I assume it has something to do with 3306, since that's
the default.
I remember when I first installed MySQL on my computer, it would never
get past the configuration wizard, also because of a port/firewall
issue. So I uninstalled it, and then reinstalled it with the firewall
off and it worked fine. And this works fine too with the firewall off, I
just need to figure out what the criteria are for the new rule I need.
BartlebyScrivener wrote: John,
Yep, different module. I'll watch the thread. Perhaps once you get connected, we should make a mini-HOWTO for XP users while it's fresh in your mind, because this question seems to come up a lot, and beginners would probably appreciate a short howto that would perhaps detail how to set up either mysqldb, mxodbc, or both on XP and get Python talking to MySQL.
I think no matter which you choose, you will benefit from downloading the mysql connector and adding your mysql db to datasources on XP. Then you can access the db just by using the name you gave it in the datasources panel, e.g. driv="bbdatabank"
rick
Well, I'm not too sure I need to do this now. The problem wasn't
anything to do with mysqldb after all, it was just that my firewall
wasn't allowing the connection. But with the firewall off, everything
seems to work fine.
>> But with the firewall off, everything seems to work fine.
Whatever works. But I'm having trouble imagining how a firewall would
interfere with you accessing your own db on localhost.
BartlebyScrivener wrote: But with the firewall off, everything seems to work fine.
Whatever works. But I'm having trouble imagining how a firewall would interfere with you accessing your own db on localhost.
I don't know either. Something to do with the ports it's trying to use I
guess.
Dennis Lee Bieber wrote: On Sat, 13 May 2006 14:49:06 -0400, John Salerno <jo******@NOSPAMgmail.com> declaimed the following in comp.lang.python:
Yeah, that's actually what I'm trying to do now. I'm not sure how to define it, but I assume it has something to do with 3306, since that's the default. What firewall application?
Zone Alarm, that I use, pops up a warning that "xyz" is trying to act as a server -- I just had to configure it to allow server for local and block internet.
Norton Internet Security. Usually it will pop up a warning and I can
accept or decline it, but it doesn't do it in this case. It just won't
connect to the database unless it's disabled. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: SillyChild |
last post by:
Hi all,
I'm trying to run PHP in my Apache on windows XP and so far it's not
working. I have been looking at various installtion pages and all they talk
about is php4apache2.dll. But where is...
|
by: Michel |
last post by:
Is there a free PHP scipts where a admin after loggin-in, knowing
nothing about PHP or HTML, can online change his pages like using a
wordprocessor like MS-word?
Thanks
|
by: Chuck |
last post by:
Hello,
Can anyone provide any kind of python database (mysql) code or point me
to a link that has this? Just simple things as maybe using a driver,
opening up a db, an insert and select. Any...
|
by: Mike Nau |
last post by:
We currently have all of our schema and testdata laid out in a large
set of sql scripts.
It currently takes about 15 minutes to run the scripts on a Dual
1.7ghz box with 1gb of ram.
Does...
|
by: hanseljose |
last post by:
How i can access a MS access database which is located in FTP server, usin vb codes.
like opendatabase("pathname')
If anybody knows pls reply me
|
by: wvmitchell |
last post by:
I am building a form to simulate the Access 2000-2003 database window, to use in Access 2007 so my users don't freak out with the new interface.
I have a program called Resource Extractor form...
|
by: shihabkb |
last post by:
Dear friends,
How to retrive database scritps like create table, create procedure scripts from database using c#.
regards
Shihab
|
by: sravan_reddy001 |
last post by:
I am creating a website. where the data to be stored in my server. I
had my webspace from some service provider.
How can i connect the website and thee database.
--website is deployed at webspace...
|
by: RaoulVdb |
last post by:
Hi,
I am a Visual Basic 6.0 user.
I have got a question:
how can I retrieve the place where my Application is located?
Thanks
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |