[英]ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'
I know this question is asked many times, and I read al lot of questions going about this, but I think mine is different. 我知道这个问题已经问过很多遍了,我读了很多与此有关的问题,但是我认为我是不同的。
I use a Mac with version 10.10.3 and a Terminal to do my commands. 我使用版本10.10.3的Mac和终端机来执行命令。
I am trying to create a local database (and I did it before), but for some reason the access is constantly denied. 我试图创建一个本地数据库(并且我之前做过),但是由于某种原因,访问被不断拒绝。
This is how my terminal looks like: 这是我的终端的样子:
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -v
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Reading history-file /Users/639/.mysql_history
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit;
Writing history-file /Users/639/.mysql_history
Bye
iMac-van:mysql 639$ /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.24 MySQL Community Server (GPL)
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database wordpress_db;
ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'wordpress_db'
As you can see I can login to mysql, but I have no permission to create a database. 如您所见,我可以登录mysql,但没有创建数据库的权限。
I tried to login like: 我尝试以以下方式登录:
$ /usr/local/mysql/bin/mysql -u root
And: 和:
$ /usr/local/mysql/bin/mysql -u root -p
I have no password, but I can enter mysql without one, but then I cannot create a database. 我没有密码,但没有密码也可以输入mysql,但是无法创建数据库。
Select current_user(); 选择current_user(); returns this:
返回此:
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost |
+----------------+
1 row in set (0,00 sec)
try to start mysql with --skip-grant-tables 尝试使用--skip-grant-tables启动mysql
mysqld --skip-grant-tables
then connect to your mysqld without username/password using mysql command line 然后使用mysql命令行连接到没有用户名/密码的mysqld
shell> mysql
then issue command 然后发出命令
> mysql> UPDATE mysql.user SET Password=PASSWORD('MyNewPass')
> WHERE User='root'; mysql> FLUSH PRIVILEGES;
First, try this command: 首先,尝试以下命令:
sudo dpkg-reconfigure mysql-server-5.5
but replace 5.5 with your current mysql-server version, and you will be asked for the new root password. 但是将5.5替换为当前的mysql服务器版本,系统将要求您输入新的root密码。
If that doesn't work, try these instructions from the manual. 如果这样不起作用,请尝试使用手册中的这些说明 。
I had the same issue. 我遇到过同样的问题。 All I had to do was to log out of the shell and log in again using
mysql -u root -p
into my mysql shell. 我要做的就是注销外壳,然后使用
mysql -u root -p
再次登录到我的mysql shell中。
This will then prompt for a password. 然后将提示您输入密码。 Since I didn't use a password while setting up, I pressed enter and that was it for me.
由于设置时未使用密码,因此按Enter键就可以了。
I hope this works for you too :) . 我希望这也对您有用:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.