pymysql.err.OperationalError: (1045, "Access denied for user 'MYID'@'localhost' (using password: NO)")
Using a mysql client or console you should execute something like this:
grant all privileges on DBNAME.* to MYID@localhost identified by 'MYPW';
using a user with grant privilege (usually root
).
Of course you can narrow down the privileges that you grant from: all privileges
to let's say: select,insert,update,delete
, depending on the case.
To access the console with root open a terminal window and write:
mysql -uroot -p
and provide the password or for passwordless root:
mysql -uroot
In case you do not know the root password follow this guide: https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
In case you are on a company/university workstation with no privileges to perform the above operation, ask from the administrator to grant the privileges.
Related videos on Youtube
user9578771
Updated on June 04, 2022Comments
-
user9578771 almost 2 years
I am running a flask web server on server A, and I need to access a SQL database in remote server B.
I am getting this error.
pymysql.err.OperationalError: (1045, "Access denied for user 'MYID'@'localhost' (using password: NO)")
Can someone help me??
Below is my code:
from flask import Flask, render_template, request from flask.ext.mysql import MySQL app = Flask(__name__) app.config['MYSQL_HOST']='IP OF SERVER B' app.config['MYSQL_PORT']='SERVER B PORT NUMBER' app.config['MYSQL_USER']='MYID' app.config['MYSQL_PASSWORD']='MYPW' app.config['MYSQL_DB']='DBNAME' mysql=MySQL(app) mysql.init_app(app) @app.route('/') def index(): cur = mysql.get_db().cursor() cur.execute('''SQLQUERY;''') rv=cur.fetchall() return str(rv)
-
Marinos An about 6 yearshave you granted privileges on user
MYID
for the schemaDBNAME
? -
user9578771 about 6 yearsthanks for the comment!! is this what I am supposed to do?
mysql > GRANT ALL PRIVILEGES ON DBNAME.* TO 'MYID'@'localhost'
-
Marinos An about 6 yearsyes using an account with grant privilege, see answer below
-
-
user9578771 about 6 yearsthanks for the help ! when I try this,
grant all privileges on DBNAME.* to MYID@localhost identified by 'MYPW';
i get the following error ERROR 1044 (42000): Access denied for user 'MYID'@'%' to database 'DBNAME' could this be due to administrator settings? -
Marinos An about 6 yearsHave you used root for executing this?
-
user9578771 about 6 yearsno.. i did not have root access. won't work otherwise right?
-
Marinos An about 6 yearsNo, but since it is a local installation, it is not difficult to have root access on mysql.
-
user9578771 about 6 yearsonly the administrator (in the team) has the root access .. :( so I don;t know the pw for the following login
mysql -uroot -p
. In this case I should contact the admin user right? thank you so much ;D -
user9578771 about 6 yearsThe admin made the change, but still the same message. However using the following shell command in server A, I was able to make the SQL connection to server B.
ssh -p PORTNUM -CNf -L3307:127.0.0.1:3306 MYID@SERVERB'sIP
thenmysql -u MYID -h 127.0.0.1 -P 3307 -e "use DBNAME; $query;
Wondering what's the difference with flask? -
Marinos An about 6 yearsAt flask use:
127.0.0.1
as host /3307
as port, or ask from the admin to grant access toMYID@your-ip
, to access directly the db server. The error pasted in the original post was misleading:Access denied for user 'MYID'@'localhost'
, since you never mentioned anything about port-forwarding before. -
user9578771 almost 6 yearsthe admin made the change as follows:
grant all privileges on DBNAME.* to 'MYID'@'%' identified by 'MYPW';
shouldn't this enable access from any ip? -
Marinos An almost 6 yearsany ip except from localhost! (which is what db server sees when
port-forwarding
is used). In mysql for localhost you need an additional grant.