I've tried multiple solutions from * but haven't had any success. I'm on Mac OSX (Sierra 10.12.3) trying to create a new database and user. From terminal I enter:
我尝试过*的多种解决方案,但是没有成功。我在Mac OSX (Sierra 10.12.3)上尝试创建一个新的数据库和用户。我从终端输入:
mysql -u root
which outputs this error:
输出这个错误:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
错误1045(28000):用户“root”@“localhost”访问被拒绝(使用密码:NO)
To try and resolve it I stopped mysql from 'System Preferences', then from terminal typed:
为了解决这个问题,我将mysql从“系统首选项”中删除,然后从终端类型中删除:
sudo mysqld_safe —skip-grant-tables
I opened a second tab and entered:
我打开第二个标签,输入:
mysql -u root
Then from in mysql:
然后从mysql:
update mysql.user set password_expired = 'N', authentication_string=PASSWORD('newpassword') where user = 'root';
flush privileges;
I then restart the computer (killing the process with CMD + C doesn't work). After restarting, trying mysql -u root
still produces the same error.
然后我重新启动计算机(用CMD + C杀死进程无效)。重新启动后,尝试使用mysql -u根仍然会产生相同的错误。
I am able to access mysql via a MySQL client and a non-root user.
我可以通过mysql客户端和非根用户访问mysql。
Any help is appreciated.
任何帮助都是感激。
8 个解决方案
#1
6
Just to confirm: You are sure you are running MySQL 5.7, and not MySQL 5.6 or earlier version. And the plugin column contains "mysql_native_password". (Before MySQL 5.7, the password hash was stored in a column named password. Starting in MySQL 5.7, the password column is removed, and the password has is stored in the authentication_string column.) And you've also verified the contents of authentication string matches the return from PASSWORD('mysecret'). Also, is there a reason we are using DML against the mysql.user table instead of using the SET PASSWORD FOR syntax? – spencer7593
确认一下:您确定正在运行MySQL 5.7,而不是MySQL 5.6或更早的版本。插件列包含“mysql_native_password”。(在MySQL 5.7之前,密码散列存储在一个名为password的列中。从MySQL 5.7开始,删除密码列,密码存储在authentication_string列中。您还验证了身份验证字符串的内容与来自密码('mysecret')的返回匹配。还有,我们使用DML来对付mysql有什么原因吗?用户表而不是使用设置的密码进行语法?——spencer7593
So Basically Just make sure that the Plugin Column contains "mysql_native_password".
因此,基本上只需确保插件列包含“mysql_native_password”。
Not my work but I read comments and noticed that this was stated as the answer but was not posted as a possible answer yet.
不是我的工作,但我读了评论,并注意到这是一个答案,但还没有张贴作为一个可能的答案。
#2
19
For security reason mysql -u root wont work untill you pass -p in command so try with below way
出于安全原因,mysql -u root在通过-p命令之前不能工作,所以请尝试下面的方法
mysql -u root -p[Enter]
//enter your localhost password
#3
4
mysql -u root -p;
And mysql will ask for the password
mysql会要求输入密码
#4
2
You must run your mysql by xampp-controle.exe in folder XAMPP. After that login:
必须通过xampp-controle来运行mysql。exe XAMPP的文件夹。在那之后登录:
mysql -u root
#5
1
Is it possible the root password is not what you think it is? Have you checked the file /root/.mysql_secret for the password? That is the default location for the automated root password that is generated from starting from version 5.7.
根密码是否可能不是你想的那样?你检查过文件/root/了吗?mysql_secret密码吗?这是从5.7版本开始生成的自动root密码的默认位置。
cat /root/.mysql_secret
#6
1
If you need to skip the password prompt for some reason, you can input the password in the command (Dangerous)
如果由于某种原因需要跳过密码提示符,可以在命令(危险)中输入密码
mysql -u root --password=secret
#7
0
just use:
只使用:
$ sudo mysql
without the "-u root" parameter.
没有“-u root”参数。
#8
0
Try this (on Windows, i don't know how in others), if you have changed password a now don't work.
试试这个(在Windows上,我不知道在其他情况下如何),如果你现在更改了密码a,那就不行。
1) kill mysql 2) back up /mysql/data folder 3) go to folder /mysql/backup 4) copy files from /mysql/backup/mysql folder to /mysql/data/mysql (rewrite) 5) run mysql
1)关闭mysql 2)备份/mysql/data文件夹3)进入文件夹/mysql/backup 4)从/mysql/backup/mysql文件夹中拷贝文件到/mysql/data/mysql(重写)5)运行mysql
In my XAMPP on Win7 it works.
在Win7上的XAMPP中,它是有效的。
#1
6
Just to confirm: You are sure you are running MySQL 5.7, and not MySQL 5.6 or earlier version. And the plugin column contains "mysql_native_password". (Before MySQL 5.7, the password hash was stored in a column named password. Starting in MySQL 5.7, the password column is removed, and the password has is stored in the authentication_string column.) And you've also verified the contents of authentication string matches the return from PASSWORD('mysecret'). Also, is there a reason we are using DML against the mysql.user table instead of using the SET PASSWORD FOR syntax? – spencer7593
确认一下:您确定正在运行MySQL 5.7,而不是MySQL 5.6或更早的版本。插件列包含“mysql_native_password”。(在MySQL 5.7之前,密码散列存储在一个名为password的列中。从MySQL 5.7开始,删除密码列,密码存储在authentication_string列中。您还验证了身份验证字符串的内容与来自密码('mysecret')的返回匹配。还有,我们使用DML来对付mysql有什么原因吗?用户表而不是使用设置的密码进行语法?——spencer7593
So Basically Just make sure that the Plugin Column contains "mysql_native_password".
因此,基本上只需确保插件列包含“mysql_native_password”。
Not my work but I read comments and noticed that this was stated as the answer but was not posted as a possible answer yet.
不是我的工作,但我读了评论,并注意到这是一个答案,但还没有张贴作为一个可能的答案。
#2
19
For security reason mysql -u root wont work untill you pass -p in command so try with below way
出于安全原因,mysql -u root在通过-p命令之前不能工作,所以请尝试下面的方法
mysql -u root -p[Enter]
//enter your localhost password
#3
4
mysql -u root -p;
And mysql will ask for the password
mysql会要求输入密码
#4
2
You must run your mysql by xampp-controle.exe in folder XAMPP. After that login:
必须通过xampp-controle来运行mysql。exe XAMPP的文件夹。在那之后登录:
mysql -u root
#5
1
Is it possible the root password is not what you think it is? Have you checked the file /root/.mysql_secret for the password? That is the default location for the automated root password that is generated from starting from version 5.7.
根密码是否可能不是你想的那样?你检查过文件/root/了吗?mysql_secret密码吗?这是从5.7版本开始生成的自动root密码的默认位置。
cat /root/.mysql_secret
#6
1
If you need to skip the password prompt for some reason, you can input the password in the command (Dangerous)
如果由于某种原因需要跳过密码提示符,可以在命令(危险)中输入密码
mysql -u root --password=secret
#7
0
just use:
只使用:
$ sudo mysql
without the "-u root" parameter.
没有“-u root”参数。
#8
0
Try this (on Windows, i don't know how in others), if you have changed password a now don't work.
试试这个(在Windows上,我不知道在其他情况下如何),如果你现在更改了密码a,那就不行。
1) kill mysql 2) back up /mysql/data folder 3) go to folder /mysql/backup 4) copy files from /mysql/backup/mysql folder to /mysql/data/mysql (rewrite) 5) run mysql
1)关闭mysql 2)备份/mysql/data文件夹3)进入文件夹/mysql/backup 4)从/mysql/backup/mysql文件夹中拷贝文件到/mysql/data/mysql(重写)5)运行mysql
In my XAMPP on Win7 it works.
在Win7上的XAMPP中,它是有效的。