MySQL的“ERROR 1698(28000):拒绝访问用户‘根’@‘localhost’的”

问题描述:

我用下面的版本安装了MySQL:MySQL的“ERROR 1698(28000):拒绝访问用户‘根’@‘localhost’的”

[email protected]:~$ mysql -V 
mysql Ver 14.14 Distrib 5.7.15, for Linux (x86_64) using EditLine wrapper 

我记得我没有设定的密码root用户在安装过程中。但是,如果我试图简单地使用mysql命令来启动它,我收到以下错误:

[email protected]:~$ mysql 
ERROR 1045 (28000): Access denied for user 'kurt'@'localhost' (using password: NO) 

同样,作为root用户,

[email protected]:~$ mysql -u root 
ERROR 1698 (28000): Access denied for user 'root'@'localhost' 

我想下面就Resetting the Root Password: Unix and Unix-Like Systems的说明;我在我的主目录中创建了文本文件,然后从那里尝试使用--init-file选项启动MySQL服务器。然而,我又得到了权限错误:

[email protected]:~$ mysqld_safe --init-file=mysql-init & 
[1] 18340 
[email protected]:~$ /usr/bin/mysqld_safe: 548: /usr/bin/mysqld_safe: cannot create /var/lib/mysql/mysqld_safe.pid: Permission denied 
2016-09-20T14:57:04.753720Z mysqld_safe Logging to '/var/log/mysql/error.log'. 
cat: /var/run/mysqld/mysqld.pid: Permission denied 
rm: cannot remove '/var/run/mysqld/mysqld.pid': Permission denied 
2016-09-20T14:57:04.780206Z mysqld_safe Fatal error: Can't remove the pid file: 
/var/run/mysqld/mysqld.pid 
Please remove it manually and start /usr/bin/mysqld_safe again; 
mysqld daemon not started 
/usr/bin/mysqld_safe: 135: /usr/bin/mysqld_safe: cannot create /var/log/mysql/error.log: Permission denied 
rm: cannot remove '/var/lib/mysql/mysqld_safe.pid': Permission denied 

我读过关于在Cant connect to Mysql server ; Can't create/write the pid file类似的错误,在这里所提出的解决方案是将MySQL用户分配到/var/run/mysqld目录。不过,如果我试试这个,我得到“不允许操作”:

[email protected]:~$ chown mysql:mysql /var/run/mysqld 
chown: changing ownership of '/var/run/mysqld': Operation not permitted 

如何让MySQL工作任何想法?

+0

你必须以root身份运行系统命令,而不是像kurt ;-) –

我注意到一个解决方案是运行mysqlsudo

[email protected]:~$ sudo mysql 
sudo: unable to resolve host kurt-ThinkPad 
[sudo] password for kurt: 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 14 
Server version: 5.7.15 MySQL Community Server (GPL) 

Copyright (c) 2000, 2016, 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> 

(我得到了这个建议来自https://bbs.archlinux.org/viewtopic.php?id=154010)。