[英]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. 我刚刚在Mac OSX上安装了mysql,并可以轻松地在shell中打开它并获得对它附带的数据库和表的访问。
Now I want to create a database in Python using mysql-connector/python 现在我想使用mysql-connector / python在Python中创建数据库
Before doing that I figured it would be wise to set a user name and password in mysql. 在此之前,我认为在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.
我的目标是设置用户名和密码,以便我可以简单地将其提供给python的mysql-connector,并最终在python环境中执行sql查询。 Here is what I tried at the mysql command prompt:
这是我在mysql命令提示符下尝试的操作:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd'); 为'root'@'localhost'设置密码= PASSWORD('newpwd');
And I get the error message: 我收到错误消息:
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql' 错误1044(42000):用户'@'localhost'对数据库'mysql'的访问被拒绝
So I tried the UPDATE METHOD: 所以我尝试了UPDATE METHOD:
UPDATE mysql.user SET Password = PASSWORD('newpwd') WHERE User = 'root'; UPDATE mysql.user SET密码= PASSWORD('newpwd')WHERE用户='root';
and I get the error message: 我收到错误消息:
ERROR 1142 (42000): UPDATE command denied to user ''@'localhost' for table 'user' 错误1142(42000):表'user'的用户'@'localhost'拒绝UPDATE命令
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? 那么,有谁知道我为什么被拒绝以及如何进行更改以创建最终在python环境中的mysql connect中使用的用户和密码?
Sounds like you are not properly authenticated. 听起来好像您的身份验证不正确。 Make sure you are authenticated with root user
确保您已通过root用户认证
Access denied for user ''@'localhost' to database 'mysql'
should look like Access denied for user ''@'localhost' to database 'mysql'
Access denied for user 'root'@'localhost' to database 'mysql'
Otherwise you are not logged in as root, but rather as an anonymous user. 否则,您将不是以root用户身份登录,而是以匿名用户身份登录。
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. Ofc,当您用root登录时,不会收到该消息,但是对于任何不具有正确权限的用户名,您都会得到它。
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');"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.