I am trying to host a Python/Mysql project online with PythonAnywhere. When I attempt to connect to the database with: (host and password changed obviously)
conn = mysql.connector.connect(host='host',user="BobbyQ",password='password',db='mm-database')
I get this error:
mysql.connector.errors.ProgrammingError: 1044 (42000): Access denied for user 'BobbyQ'#'%' to database 'mm-database'
If I run SHOW GRANTS from Mysql console I get this:
mysql> SHOW GRANTS;
+------------------------------------------------------------------------------------------------+
| Grants for BobbyQ#% |
+------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'BobbyQ'#'%' IDENTIFIED BY PASSWORD <secret> WITH MAX_USER_CONNECTIONS 3 |
| GRANT ALL PRIVILEGES ON `BobbyQ$default`.* TO 'BobbyQ'#'%' |
| GRANT ALL PRIVILEGES ON `BobbyQ$mm-database`.* TO 'BobbyQ'#'%' |
+------------------------------------------------------------------------------------------------+
I should be able to connect to the database at this point but I don't why I can't. How can I solve?
With sudo user connect to the database (in the terminal) and create newuser:
CREATE USER 'newuser'#'localhost' IDENTIFIED BY 'user_password';
then go to the mysql database with this command :
USE MYSQL
and give all access to the user (newuser) with :
GRANT ALL PRIVILEGES ON database_name.* TO 'username'#'localhost';
Write the name of the desired database instead of database_name and the desired username instead of username.
Finally :
FLUSH PRIVILEGES;
Related
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;
I have a user in mySQL database like this
And I am trying to login to mySQL on serverA from server B, in python, here is what I am currently doing,
db = MySQLdb.connect(host='IP-address-server-A', user='username', passwd='my-password', db='my-database')
And I am getting this error
(1045, "Access denied for user 'username'#'serverB' (using password: YES)")
What is going on, and why can't I connect?
Thanks for the help
show logins to the server (note that % means anyhost or wildcard)
select user,host from mysql.user;
+-----------+------------+
| user | host |
+-----------+------------+
| ajax_guy | % |
| joe7 | % |
| joe8 | % |
+-----------+------------+
show what grants exist for a certain user.
show grants for 'ajax_guy'#'%';
+----------------------------------------------------------------------
| Grants for ajax_guy#%
+----------------------------------------------------------------------
| GRANT USAGE ON *.* TO 'ajax_guy'#'%' IDENTIFIED BY PASSWORD ...
| GRANT ALL PRIVILEGES ON `ajax_stuff`.* TO 'ajax_guy'#'%'
| GRANT ALL PRIVILEGES ON `ajax_stuff`.`ajax_stuff` TO 'ajax_guy'#'%'
+----------------------------------------------------------------------
How to grant access to a certain db to a certain login.
Below we are granting all rights to the user to the so_gibberish database.
grant ALL on so_gibberish.* to 'ajax_guy'#'%';
Look at grants in effect now for that login
+----------------------------------------------------------------------
| Grants for ajax_guy#%
+----------------------------------------------------------------------
| GRANT USAGE ON *.* TO 'ajax_guy'#'%' IDENTIFIED BY PASSWORD ...
| GRANT ALL PRIVILEGES ON `ajax_stuff`.* TO 'ajax_guy'#'%'
| GRANT ALL PRIVILEGES ON `so_gibberish`.* TO 'ajax_guy'#'%'
| GRANT ALL PRIVILEGES ON `ajax_stuff`.`ajax_stuff` TO 'ajax_guy'#'%'
+----------------------------------------------------------------------
Create a new login drew_saturday with a password friday987.
He has all privileges on database so_gibberish and can login from any host (%)
grant ALL on so_gibberish.* to 'drew_saturday'#'%' IDENTIFIED BY 'friday987';
select user,host,password from mysql.user where user='drew_saturday';
+---------------+------+-------------------------------------------+
| user | host | password |
+---------------+------+-------------------------------------------+
| drew_saturday | % | *4600ED0F377308959665877BD327D4788DC2071F |
+---------------+------+-------------------------------------------+
That password above is the hashed password by the way.
Note: for MySQL 5.7 the command above would be:
select user,host,authentication_string from mysql.user where user='drew_saturday';
Mysql manual page on Grant. Do not grant excessive rights to users using grant ALL on *. .... That would be for all database in the system. Just read the manual and less is more.
Sometimes, admins want to grant access to just a handful of tables in a database (not all tables in it) to a login. The manual is a must read on this.
And one last thing. 'drew_saturday'#'%' is a different login than 'drew_saturday'#'NOT-local' (borrowing from your title). They are different logins with different rights. That is the point of the first thing I wrote way up there.
I am trying to get started with the following github package: py-gameday.
I installed mysql with brew mysql and created a root password:
> mysqladmin -u root password 'xxx'
I then created a user:
> mysql -uroot -p
Enter password: xxx
CREATE USER 'josh'#'localhost' IDENTIFIED BY 'yyy';
Just in case, I reset the password again:
SET PASSWORD FOR 'josh'#'localhost' = PASSWORD('yyy');
and I then updated mydb.ini with:
[db]
user=josh
password=yyy
db=gameday
I finally tried running the following:
$ mysql -D gameday < gameday.sql -p
Enter password:
ERROR 1044 (42000): Access denied for user 'josh'#'localhost' to database 'gameday'
In this last step, I tried entering 'xxx' and 'yyy', but none of them worked. Why?
You need to GRANT access for the user 'josh' to the database 'test'.
GRANT ALL ON test.* TO 'josh'#'localhost';
As long as you don't have NO_AUTO_CREATE_USER set, you can skip the CREATE USER... the following will create the USER and GRANT access in one hit...
GRANT ALL ON test.* TO 'josh'#'localhost' IDENTIFIED BY 'yyy';
You have to also set privileges for that user
GRANT ALL ON test.* TO 'josh'#'localhost';
I have just installed mysql on Mac OSX and can easily open it in a shell and gain access to the databases and tables that come with it.
Now I want to create a database in Python using mysql-connector/python
Before doing that I figured it would be wise to set a user name and password in mysql.
I have tried using the following but get error messages.
My GOAL is to set a user name and a password so that I may simply provide it to mysql-connector for python, and ultimately execute sql queries from the python environment. Here is what I tried at the mysql command prompt:
SET PASSWORD FOR 'root'#'localhost' = PASSWORD('newpwd');
And I get the error message:
ERROR 1044 (42000): Access denied for user ''#'localhost' to database 'mysql'
So I tried the UPDATE METHOD:
UPDATE mysql.user SET Password = PASSWORD('newpwd')
WHERE User = 'root';
and I get the error message:
ERROR 1142 (42000): UPDATE command denied to user ''#'localhost' for table 'user'
So does anyone know why I get denied and how I can make the changes to create a user and a password that I may ultimately use in mysql connect in the python environment?
Sounds like you are not properly authenticated. Make sure you are authenticated with root user
Access denied for user ''#'localhost' to database 'mysql'
should look like
Access denied for user 'root'#'localhost' to database 'mysql'
Otherwise you are not logged in as root, but rather as an anonymous user.
Ofc, when you are logged in with root, you won'T get that message, but you would get it for any username that does not have the proper rights.
start your query with authentication
mysql -u USERNAME -pPASSWORD -h HOSTNAMEORIP DATABASENAME
example:
mysql --port=3307 --host=127.0.0.1 -u root --password=thisismypass test -e "LOAD DATA LOW_PRIORITY LOCAL INFILE '%pathuser%' INTO TABLE `user_log`...."
in your case probably
mysql -u root "SET PASSWORD FOR 'root'#'localhost' = PASSWORD('newpwd');"
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()