1

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?

1 Answer 1

1

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');"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.