Does anyone know how to change the connections.py file in /usr/lib/python2.4/site-packages/MySQLdb/connections.py"
to a specific user?
The error I get is:
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
Attrched is the begiining of the file: -
"""
-
-
This module implements connections for MySQLdb. Presently there is
-
only one class: Connection. Others are unlikely. However, you might
-
want to make your own subclasses. In most cases, you will probably
-
override Connection.default_cursor with a non-standard Cursor class.
-
-
"""
-
import cursors
-
from _mysql_exceptions import Warning, Error, InterfaceError, DataError, \
-
DatabaseError, OperationalError, IntegrityError, InternalError, \
-
NotSupportedError, ProgrammingError
-
import types, _mysql
-
-
-
def defaulterrorhandler(connection, cursor, errorclass, errorvalue):
-
"""
-
-
If cursor is not None, (errorclass, errorvalue) is appended to
-
cursor.messages; otherwise it is appended to
-
connection.messages. Then errorclass is raised with errorvalue as
-
the value.
-
-
You can override this with your own error handler by assigning it
-
to the instance.
-
-
"""
-
error = errorclass, errorvalue
-
if cursor:
-
cursor.messages.append(error)
-
else:
-
connection.messages.append(error)
-
del cursor
-
del connection
-
raise errorclass, errorvalue
-
-
-
class Connection(_mysql.connection):
-
-
"""MySQL Database Connection Object"""
-
-
default_cursor = cursors.Cursor
-
-
def __init__(self, *args, **kwargs):
-
"""
-
-
Create a connection to the database. It is strongly recommended
-
that you only use keyword parameters. Consult the MySQL C API
-
documentation for more information.
-
-
host
-
string, host to connect
-
-
user
-
string, user to connect as
-
-
passwd
-
string, password to use
8 9329
Hello and welcome to the Python forum on TSDN.
The problem is not with /usr/lib/python2.4/site-packages/MySQLdb/connections.py
The error I get is:
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)")
The problem is that way you are calling it. Please post your code (not the library code). I'll dig up some examples that I have written which will help.
Hello and welcome to the Python forum on TSDN.
The problem is not with /usr/lib/python2.4/site-packages/MySQLdb/connections.py"
The problem is that way you are calling it. Please post your code (not the library code). I'll dig up some examples that I have written which will help.
If this is a shared machine on "unix" you will most likely NOT have a root login and you will need the admin to create an account for you. If this is your own machine or you have an account already set up then you can get a connection like this: - from MySQLdb import *
-
# replace servername, username and password with your account info
-
dbconnect = connect(host=servername, user=username, passwd=password)
-
dbcursor = dbconnect.cursor()
-
# once you have a cursor, you can send SQL commands to the DB, like:
-
dbcursor.execute('SET autocommit=1')
Here are some useful classes and helper functions that I wrote.
Hi and thanks for getting back to me here is the code you asked for...
and the error again
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)") -
import MySQLdb
-
import os
-
from splicegraph_jan06 import *
-
-
spliceCalcs={'hg17_JAN06':
-
TableGroup(db='SPLICE_JAN06',suffix='hg17',clusters='cluster_hg17',
-
exons='isoform_exon_form_hg17',splices='splice_verificat
-
ion_hg17',
-
genomic='genomic_cluster_hg17',mrna='isoform_mrna_seq_hg
-
17',
-
protein='isoform_protein_seq_hg17'),
-
'mm7_JAN06':
-
TableGroup(db='SPLICE_JAN06',suffix='mm7',clusters='cluster_mm17',
-
exons='isoform_exon_form_mm7',splices='splice_verificati
-
on_mm7',
-
genomic='genomic_cluster_mm7',mrna='isoform_mrna_seq_mm7
-
',
-
protein='isoform_protein_seq_mm7')
-
}
-
-
-
def getUserCursor(db):
-
'get a cursor as the current user'
-
db=MySQLdb.connect(db=db,read_default_file=os.environ['HOME']+'/.my.cnf',com
-
press=True)
-
return db.cursor()
-
-
def getSpliceGraphFromDB(dbgroup,loadAll=False):
-
"""load data from MySQL using the designated database table group.
-
If loadAll true, then load the entire splice graph into memory."""
-
cursor=getUserCursor(dbgroup.db)
-
import sys
-
print >>sys.stderr,'Reading database schema...'
-
idDict={}
-
tables=describeDBTables(dbgroup.db,cursor,idDict)
-
if hasattr(dbgroup,'suffix'):
-
tables=suffixSubset(tables,dbgroup.suffix) # SET OF TABLES ENDING IN JUN
-
03
-
idDict=indexIDs(tables) # CREATE AN INDEX OF THEIR PRIMARY KEYS
-
for t in dbgroup.values():
-
if t is not None and '.' in t and t not in tables: # THIS TABLE COMES FR
-
OM ANOTHER DATABASE...
-
tables[t]=SQLTable(t,cursor) # SO GET IT FROM OTHER DATABASE
-
-
# LOAD DATA & BUILD THE SPLICE GRAPH
-
return loadSpliceGraph(tables,dbgroup.clusters,dbgroup.exons,dbgroup.splices
-
,
-
dbgroup.genomic,dbgroup.mrna,dbgroup.protein,loadAll)
-
-
def localCopy(localFile,cpCommand):
-
'if not already present on local file location, run cpCommand'
-
if not os.access(localFile,os.R_OK):
-
cmd=cpCommand % localFile
-
print 'copying data:',cmd
-
exit_code=os.system(cmd)
-
if exit_code!=0:
-
raise OSError((exit_code,'command failed: %s' % cmd))
-
return localFile
Hi and thanks for getting back to me here is the code you asked for...
and the error again
_mysql_exceptions.OperationalError: (1045, "Access denied for user 'root'@'localhost' (using password: NO)") -
import MySQLdb
-
import os
-
def getUserCursor(db):
-
'get a cursor as the current user'
-
db=MySQLdb.connect(db=db,read_default_file=os.environ['HOME']+'/.my.cnf',com
-
press=True)
-
return db.cursor()
First I'd see if you can make this work - # replace servername, username and password with your account info
-
dbconnect = connect(host=servername, user=username, passwd=password)
-
dbcursor = dbconnect.cursor()
-
Then, if that works, check to see if your
my.cnf
is set up correctly. I should look like this:
You can specify connection parameters in the [client] section of an option file. The relevant section of the file might look like this:
[client]
host=host_name
user=user_name
password=your_pass
Section 4.3.2, “Using Option Files”, discusses option files further.
according to MySQL docs.
It also looks like you can specify other that "client" group using
read_default_group
configuration group to use from the default file
but mysqld docs are not very clear on that.
Hi again,
I enter the following lines you recommend
dbconnect = connect(host=hostname, user=root, passwd=*******)
dbcursor = dbconnect.cursor()
and get the following error?
File "/home/pedro/pygr/tests/lldb_jan06.py", line 22, in ?
dbconnect = connect(host=hostname, user=root, passwd=*******)
NameError: name 'connect' is not defined
First I'd see if you can make this work - # replace servername, username and password with your account info
-
dbconnect = connect(host=servername, user=username, passwd=password)
-
dbcursor = dbconnect.cursor()
-
Then, if that works, check to see if your
my.cnf
is set up correctly. I should look like this:
You can specify connection parameters in the [client] section of an option file. The relevant section of the file might look like this:
[client]
host=host_name
user=user_name
password=your_pass
Section 4.3.2, “Using Option Files”, discusses option files further.
according to MySQL docs.
It also looks like you can specify other that "client" group using
read_default_group
configuration group to use from the default file
but mysqld docs are not very clear on that.
Hi again,
I enter the following lines you recommend
dbconnect = connect(host=hostname, user=root, passwd=*******)
dbcursor = dbconnect.cursor()
and get the following error?
File "/home/pedro/pygr/tests/lldb_jan06.py", line 22, in ?
dbconnect = connect(host=hostname, user=root, passwd=*******)
NameError: name 'connect' is not defined
Sorry, that was a snippet.. should be: - from MySQLdb import *
-
dbconnect = connect(host=hostname, user=root, passwd=*******)
-
dbcursor = dbconnect.cursor()
-
as in my reply #3 above.
Ok that worked but now I get another error from a second py program...
File "/home/pedro/pygr/tests/lldb_jan06.py", line 34, in getSpliceGraphFromDB
tables=describeDBTables(dbgroup.db,cursor,idDict)
File "/usr/lib/python2.4/site-packages/pygr/sqlgraph.py", line 212, in describeDBTables
cursor.execute('use %s' % name)
AttributeError: 'NoneType' object has no attribute 'execute'
Here is the portion of the script: -
def describeDBTables(name,cursor,idDict):
-
"""
-
Get table info about database <name> via <cursor>, and store primary keys
-
in idDict, along with a list of the tables each key indexes.
-
"""
-
cursor.execute('use %s' % name)
-
cursor.execute('show tables')
-
tables={}
-
l=[c[0] for c in cursor.fetchall()]
-
for t in l:
tname=name+'.'+t
o=SQLTable(tname,cursor)
[/code]
and the original change from the other py script
[code]
def getUserCursor(db):
'get a cursor as the current user'
#db=MySQLdb.connect(db=db,read_default_file=os.env iron['HOME']+'/.my.cnf',com
#press=True)
# return db.cursor()
from MySQLdb import *
dbconnect = connect(host='localhost', user='root', passwd='retep1er')
dbcursor = dbconnect.cursor()
[code]
Incidentally I changed my /etc/mysql/my.cnf file (my only my.cnf) file
[client]
[client]
user = 'root'
password = '********'
port = 3306
socket = /var/run/mysqld/mysqld.sock
with the original configuration of the py file
[code]
def getUserCursor(db):
'get a cursor as the current user'
db=MySQLdb.connect(db=db,read_default_file=os.envi ron['HOME']+'/.my.cnf',com
press=True)
return db.cursor()
[\CODE]
and this produced the original error?
If this is a shared machine on "unix" you will most likely NOT have a root login and you will need the admin to create an account for you. If this is your own machine or you have an account already set up then you can get a connection like this: - from MySQLdb import *
-
# replace servername, username and password with your account info
-
dbconnect = connect(host=servername, user=username, passwd=password)
-
dbcursor = dbconnect.cursor()
-
# once you have a cursor, you can send SQL commands to the DB, like:
-
dbcursor.execute('SET autocommit=1')
Here are some useful classes and helper functions that I wrote.
Here for error handling example.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Randell D. |
last post by:
Folks,
I currently connect to my db with PHP code that uses non-persistent
connections. I've read that persistent connections can help performance
since a connection to the db will use an...
|
by: Mudge |
last post by:
Hi,
My hosting provider only allows me to use 50 connections to my MySQL
database that my Web site will use.
I don't know what this 50 connections means exactly. Does this mean that
only 50...
|
by: Angelos |
last post by:
I get this error mysql_pconnect Too many connections ... every now and
then.
Does anyone knows where it comes from ?
There are a lot of sites running on the server and all of them use the...
|
by: C Sharp beginner |
last post by:
I'm sorry about this verbose posting. This is a follow-up
to my yesterday's posting. Thanks William for your reply.
I understand it is a good practice to open connections as
late as possible and...
|
by: Bob |
last post by:
We have a production web site that's data intensive (save user input to DB
and query for displaying) with the ASP.NET app part on one W2K server and
SQL 2000 DB on another W2K server. I have set...
|
by: Peter Proost |
last post by:
Hi Group,
I've got an interesting problem, I don't know if this is the right group but
I think so because everything I've read about it so far says it's a .net
problem. Here's the problem, we're...
|
by: elyob |
last post by:
Not really tried going two ways at once, but I have an include_once
connection to a mysql_database, now I need to retrieve info from a second
mysql_database ..
My mysql_connects are getting...
|
by: marcfischman |
last post by:
Please help. I have a website running on a linux/apache/mysql/php
server. I receive about 8,000-10,000 visitors a day with about 200,000
to 300,000 page views. The server is a RedHat Linux...
|
by: PRP |
last post by:
Hi,
Our DBA has complained about the large number of connections from the
aspnet_wp process.
We have multiple web applications deployed in different virtual
directories. I read that the way...
|
by: Usman Jamil |
last post by:
Hi
I've a class that creates a connection to a database, gets and loop on a
dataset given a query and then close the connection. When I use netstat
viewer to see if there is any connection open...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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,...
| |