无法在新安装的服务器版本5.7.18-0ubuntu0.17.04.1 (Ubuntu)上连接到mysql on localhost over TCP
这样做是可行的:
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.7.18-0ubuntu0.17.04.1 (Ubuntu)这并不是:
# mysql -h 127.0.0.1
ERROR 1698 (28000): Access denied for user 'root'@'localhost'在客户机内部,我看到mysql被配置为在127.0.0.1上侦听:
mysql> show variables like '%bind%';
+---------------+-----------+
| Variable_name | Value |
+---------------+-----------+
| bind_address | 127.0.0.1 |
+---------------+-----------+
1 row in set (0.00 sec)它确实在倾听:
# netstat -tl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost:mysql 0.0.0.0:* LISTEN因此,PHP在以下方面也失败了:
Warning: mysqli_connect(): (HY000/1698): Access denied for user 'root'@'localhost'怎么解决这个问题?也许在TCP上设置了基于密码的禁用登录?
UPDATE::localhost的意思是本地套接字,因此我为'root'@'127.0.0.1‘为TCP连接创建了另一个记录。
CREATE USER 'root'@'127.0.0.1';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1';
FLUSH PRIVILEGES;但还是不起作用:
# mysql --protocol=TCP --host=127.0.0.1
ERROR 1698 (28000): Access denied for user 'root'@'localhost'密码未设置。
mysql> SELECT host, user, authentication_string FROM mysql.user;
+-----------+------------------+-------------------------------------------+
| host | user | authentication_string |
+-----------+------------------+-------------------------------------------+
| localhost | root | |
| localhost | mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| localhost | debian-sys-maint | *4CF7B81390C295E6AF38067F3B621BBF736D3366 |
| 127.0.0.1 | root | |
+-----------+------------------+-------------------------------------------+
4 rows in set (0.01 sec)UPDATE 2:我从头开始,所以这是失败的测试:
mysql -h 127.0.0.1但是在重新创建用户之后,它就开始工作了:
DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;为什么它不能和同一个用户一起工作呢?
发布于 2017-05-07 14:36:29
您的根用户有密码吗?尝试命令
mysql -h 127.0.0.1 -u root -p如果运行mysql_secure_installation,它将阻止远程根登录。您可以尝试以下方法来重置根用户。
停止MySQL服务
#/etc/init.d/mysql stop带有--跳过-授予表的Exec MySQL服务器
#mysqld -u mysql --skip-grant-tables &Exec客户端作为根
#mysql -u root更新您的密码
mysql> update mysql.user set password=password('newpassword') where user='anotheruser';重装特权
mysql> flush privileges;杀死米舍尔德
#killall mysql启动mysql守护进程
#/etc/init.d/mysql start发布于 2017-05-09 09:02:52
这就是解决办法:
UPDATE mysql.user SET plugin='mysql_native_password' WHERE user='root' AND host ='localhost';
FLUSH PRIVILEGES;默认情况下,'root'@'localhost'被配置为通过只能使用本地unix的插件进行身份验证。此命令切换到用户的mysql_native_password插件,它与TCP (我的本地PHP安装所需的)一起工作。
在更新2之后,我比较了mysql.user在重新创建root@localhost之前和之后,并发现了plugin列中的差异。
https://stackoverflow.com/questions/43832682
复制相似问题