简体   繁体   中英

mysql setting user name and password

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');"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM