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(); returns this:
选择current_user();返回:
mysql> select current_user();
+----------------+
| current_user() |
+----------------+
| @localhost |
+----------------+
1 row in set (0,00 sec)
3 个解决方案
#1
0
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;
#2
0
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.
但是用当前的mysql-server版本替换5.5,您将被要求输入新的根密码。
If that doesn't work, try these instructions from the manual.
如果不行,试试手册上的说明。
#3
0
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.
我也有同样的问题。我所要做的就是退出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.
然后提示输入密码。因为我在设置时没有使用密码,所以我按了回车键。
I hope this works for you too :) .
我希望这对你也适用:)。
#1
0
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;
#2
0
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.
但是用当前的mysql-server版本替换5.5,您将被要求输入新的根密码。
If that doesn't work, try these instructions from the manual.
如果不行,试试手册上的说明。
#3
0
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.
我也有同样的问题。我所要做的就是退出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.
然后提示输入密码。因为我在设置时没有使用密码,所以我按了回车键。
I hope this works for you too :) .
我希望这对你也适用:)。