你在哪里运行数据库脚本/ DB位于哪里? [英] where do you run database scripts/where are DBs 'located'?

查看:60
本文介绍了你在哪里运行数据库脚本/ DB位于哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我一直在浏览MySQLdb文档,我想*我知道

我需要编写的代码(连接,光标,操作数据,
commmit等 - 虽然我可能需要更熟悉

实际的SQL命令),但这里是我的问题:我不知道在哪里

这些脚本应该被执行,或者它们应该如何使用
''找到''数据库。


真的,我对两个不同的场景有同样的问题:访问

并使用本地存储在我的PC上的数据库,

与开启的数据库相同我的网络服务器空间。我想我已经知道

主机,用户名,密码和数据库名称(事实上,就我的网络数据库而言,所有这些都是详细说明;我是假设我的本地数据库的
主机名是我计算机的名称。


但我的问题是,这些数据库脚本可以在任何地方执行,并且他们

会根据connect()参数找到数据库吗?或者我需要做什么?b $ b特别的东西?这似乎是一个类似的问题,当你

没有正确设置你的PYTHONPATH变量。我已经尝试了一些DB

的东西,但它似乎无法工作。


如果需要更多信息,我会尝试我的本地我回家后的数据库

之后。至于网络数据库,我觉得可能还有更多问题需要我不知道,因为网络编程对我来说还是新的。


所以没有实际给你一些代码和回溯,是否有关于如何设置这些脚本的一般建议?另外,有没有比这更好的文件:
http://sourceforge.net/docman/displa...group_id=22307


似乎也没有彻底,它也不包括你必须传递给查询方法的实际SQL

查询。也许我只会在$ MySQL教程中找到这些信息。


谢谢。

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.

推荐答案

在星期五,2006年5月12日14:01:51 +0000,John Salerno写道:
On Fri, 12 May 2006 14:01:51 +0000, John Salerno wrote:
好的,我一直在浏览MySQLdb文档,我想*我知道我需要编写的代码(连接,光标,操作数据,提交等等 - 尽管我可能需要更熟悉
实际的SQL命令也是),但这里是我的问题:我不知道这些脚本应该在哪里执行,或者它们应该如何找到数据库。


我自己就是一个菜鸟,但无论如何我会看到我不能提供一些有用的信息

。 />

当您发出MySQLdb.connect时,它确定数据库

操作发生的位置。如果您指定host =''localhost''",则表示您正在尝试将
连接到本地计算机。如果您指定host =''db.smurgle.net''",

您正在尝试连接到我的家庭数据库服务器。您可以以本地机器理解的任何格式指定

主机名;例如,

如果你在Linux机器上,你的/ etc / hosts文件包含如下行:

10.0.0.10 myDBserver

然后你可以使用'host =''myDBserver''" ;.


这不是一个网络编程问题,因为它使用MySQL的网络

界面。 MySQL默认使用端口3306(我认为)通过网络处理数据库

连接。

但我的问题是,这些数据库脚本可以在任何地方执行吗? br />会根据connect()参数找到DB吗?或者我需要做些特别的事吗?当你没有正确设置PYTHONPATH变量时,这似乎是一个类似的问题。我已经尝试了一些DB
的东西,但它似乎没有用。


您可以在以下任何地方执行建立连接的脚本:

1)知道如何与指定的数据库服务器通信,并且

2)有一些MySQL客户端可用。

所以没有实际给你一些代码和回溯,是否有关于如何设置这些脚本的一般建议?另外,有没有比这更好的文档:
http://sourceforge.net/docman/displa...group_id=22307

如果您遇到问题,请务必发布一些代码。 />
它看起来并不太彻底,它也不包括你必须传递给查询方法的实际SQL查询。也许我只需要在MySQL教程中找到这些信息。
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.




一些好的MySQL教程很可能是一个很大的帮助。

标准文档(你指出的那些文档)没有很多帮助

如果你是SQL的新手。您可能想要进行Google搜索。这个

将引导您访问以下页面:
http://www.kitebird.com/articles/pydbapi.html
http://www.devshed.com/c/a/Python/My...y-With-Python/

等。


Dan



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写道:
CatDude wrote:
在星期五,2006年5月12日14:01:51 +0000,John Salerno写道:
On Fri, 12 May 2006 14:01:51 +0000, John Salerno wrote:
好的,我一直在浏览MySQLdb文档,我认为*我知道我需要编写的代码类型(连接,光标,操作数据,提交等等 - 虽然我可能需要更熟悉实际的SQL命令),但这是我的问题:我不知道这些脚本应该在哪里执行,或者它们应该如何找到'数据库。
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.




非常感谢您的信息!我会再次尝试''localhost''和

看看我是否在其他地方创造了问题,也许是用命令

自己。 (我所知道的是,我创建了一个MySQL数据库并且用b / b
填充了棒球统计数据,所以我知道*至少存在*

但它是从MySQL提示本身创建,而不是使用Python。)


我也会阅读这些链接,它们看起来像我需要的东西

真的开始吧。 :)



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写道:
John Salerno wrote:
如果需要更多信息,我回家后会尝试使用本地数据库
稍​​后。
If more information is needed, I will try my local DB when I get home
later.




好​​的,我们走了:


导入MySQLdb


db = MySQLdb.connect(host =''localhost'',

user =''johnjsal'',

passwd =''seinfeld'',

db =''bbdatabank'')

cursor = db.cursor()

cursor.execute(''SELECT *来自Master'')

data = cursor.fetchall()

cursor.close()

db.close()

打印数据


输出:



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:



回溯(最近一次调用最后一次):

文件C:\Python24 \ _myscripts\db_test.py,第6行,in-toplevel-

db =''bbdatabank'')

文件C:\P ython24 \lib \site-packages \MySQLdb \ ___ ___。py",第66行,在

连接

返回连接(* args,** kwargs)

文件" C:\Python24 \lib \site-packages \ MySQLdb \connections.py",行

134,in __init __

super(连接,自我).__ init __(* args,** kwargs2)

OperationalError:(2003,无法连接到''localhost''上的MySQL服务器

(10061)")

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)")




情况是这样的:我安装了MySQL 5.0,创建了一个数据库名为

bbdatabank使用MySQL提示符。在数据库中有一个名为Master的表格,我正在测试。显然,使用connect方法发生了一些事情。也许我做错了什么。是否有一个

方式来获取有关正在发生的事情的更多信息?


谢谢。



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.


这篇关于你在哪里运行数据库脚本/ DB位于哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆