i have a flask python web site, im trying to connecto to mysql server but get
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied
for user 'root'#'xxx.xxx.251.67' (using password: YES)
i can reach the database thru mysql workbench using the data that im using in flask.
Iv tryed to flush previlegues
update root password
iv granted all permission on server to user root on %
but still get this error.
Anyone can help?
my code is
mydb = mysql.connector.connect(
host="mysql.server.com",
user="root",
password="passs123",
database="mydb"
)
select user,host from mysql.user ;
show grants for root#%;
show grant for root;
check the privileges for root#'%' on mydb;
Related
I am trying to establish a connection with a MySQL database in a python program
import mysql.connector
cnx = mysql.connector.connect(
host='localhost',
user='admin',
password='admin1234',
database='meu_banco'
)
cnx.close()
print(cnx)
but keep getting the following error:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'admin'#'localhost' (using password: YES)
Im am pretty sure that the username is admin and that I've setted 'admin1234' as the password. Anyone knows what might be happening?
Notes:
-I've also tried to use 'passwd' and 'db' instead of 'password' and 'database' keyword arguments.
-I'm using MySQL that comes with XAMPP version 8.0.2 / PHP 8.0.2 for Linux.
You are connecting to the database and afterwards you are closing the connection.
Only use cnx.close() when you want to close the database connection, it may cause an error.
If that's not the problem, you may have the user wrong, try to use the default username that MySQL Workbench has, it is root.
I am trying to connect to MySQL database in Flask as follows:
mysql = MySQL()
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = 'password'
app.config['MYSQL_DATABASE_DB'] = 'myDB'
mysql.init_app(app)
I am getting the following error:
pymysql.err.OperationalError: (1045, "Access denied for user 'myusername'#'localhost' (using password: NO)")
I tried reinstalling XAMPP but to no avail.
I have 2 issues:
Why am I getting the error for 'myusername' instead of 'root'?
How can I solve this issue?
SOLUTION:
I needed to grant the correct privilege to the specific user#localhost in MySQL.
By default in XAMPP root user doesn't have password, you can create a new one doing the following steps:
Click Admin next to MySQL on the XAMPP Control Panel to bring up the phpMyAdmin.
Choose the mysql database on the left.
Then, choose the SQL tab on the top and run the following statement:
SET Password=PASSWORD('password');
But, instead I highly recommend to create a new user:
CREATE USER 'myuser'#'%' IDENTIFIED BY 'password';
CREATE DATABASE myDB;
GRANT ALL PRIVILEGES ON myDB.* TO 'myuser'#'localhost';
So I granted all privileges to root in MySQL
mysql> GRANT ALL PRIVILEGES on *.* to 'root'#'localhost' IDENTIFIED BY 'password' with GRANT OPTION;
So after running this i get:
Query OK, 0 rows affected (0.00 sec)
But after running my code on Pycharm which accesses a local DB, I'm getting this:
django.db.utils.OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: YES)")
I'm pretty new to Python and MySQL, so I'm gonna need pretty simple yet detailed advice if anyone is willing to help. Thanks!
download the MySQL python connector from here
http://dev.mysql.com/downloads/connector/python/
then run this within a file:
import mysql.connector
con = mysql.connector.connect(user="root", password="xxxx", host="xxx.xxx.xxx.xxx")
cur = con.cursor()
After running your query make sure to commit any changes and close connections:
con.commit()
cur.close()
con.close()
Hi i have a requirement where i need to connect to remote mysql server. My application shall be running on local machine and my mysql will be running on remote server.I have tried the following code:
DB = 'gts'
DB_HOST = 'ps95074.dreamhost.com'
DB_USER = 'root'
DB_PASSWORD = 'dbadminpassword'
conn = MySQLdb.Connection(db=DB, host=DB_HOST, user=DB_USER,passwd=DB_PASSWORD)
cursor = conn.cursor()
But i am getting the following error
OperationalError: (2005, "Unknown MySQL server host 'ps95074.dreamhost.com' (1)")
Instead if i use
DB_HOST='localhost'
Everything works fine. How can same be possible with remote host.Any help shall be appreciated.
Check your firewall. That server is online and available from any machines:
> mysql -h ps95074.dreamhost.com
ERROR 1045 (28000): Access denied for user 'myuser'#'myhost' (using password: NO)
However, even if you can connect chances are good that your database user only allows local connections.
Update: I just tried it again and now it also fails using the commandline client. So clearly something is wrong with your server.
I'm trying to connect python with MySQL, but I get this error:
OperationalError: (1045, "Access denied for user 'root'#'localhost' (using password: NO)")
I'm trying to solve it for 6 hours and I fail. Can any one please help me ?
it means that you forgot the password parameter, which in mysql is not required.
from a unix command line:
$ mysql -u root
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: NO)
$ mysql -u root -p
Enter password:
<typing password>
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 47
Server version: 5.1.37-1ubuntu5.5 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
not exactly the same as logging from python,
but it's the same error, and most likely means that in your case the password argument did not make it to mysql at all.
when I type the wrong password I get a very different error on the command line:
$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'#'localhost' (using password: YES)
You didn't specified your root password.
If you are accessing mysql from remote computer... root user is by default limited to localhost connections only. Try running this to enable access from anywhere:
GRANT ALL PRIVILEGES ON *.* TO root#'%' IDENTIFIED BY "YOUR_ROOT_PASSWORD";
FLUSH PRIVILEGES;
Also check your firewall settings.
import MySQLdb
cxn = MySQLdb.connect(host = 'localhost',user = 'root',passwd = 'password', db = 'yourdatabase')
So you need to know what your password is and you need to have created a database with:
CREATE DATABASE yourdatabase;
from the mysql command line as described above.
I was getting this error because I had quotes in my config file.
[mysql]
username: 'uuuu'
password: 'pppp'
host: 'localhost'
database: 'dddd'
should have been
[mysql]
username: uuuu
password: pppp
host: localhost
database: dddd
If you don't see any value in front of the password column when you do
SELECT user, host, password FROM mysql.user;
within your mysql
In your python script don't specify the password
for example
import MySQLdb
db = MySQLdb.connect(host="localhost", # your host, usually localhost
user="root", # your username
passwd="", # your password
db="dynamo",
port = 3306) # name of the data base
# you must create a Cursor object. It will let
# you execute all the queries you need
cur = db.cursor()
# Use all the SQL you like
cur.execute("select * from SomeTable limit 10")
# print all the first cell of all the rows
for row in cur.fetchall():
print(row[0])
db.close()