Mysql 8 远程访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50570592/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:56:25  来源:igfitidea点击:

Mysql 8 remote access

mysqlauthenticationmysql-8.0

提问by sHaDeoNeR

I usualy setup correctly MySQL for having remote access.

我通常正确设置 MySQL 以进行远程访问。

And currently I got stuck with MySQL 8.

目前我被 MySQL 8 困住了。

The first thing is that on the mysql.conf.d/mysqld.cnf , I don't have any bind-address line, so I added it by hand (bind-address 0.0.0.0) And I granted access to the user on '%'

第一件事是在 mysql.conf.d/mysqld.cnf 上,我没有任何绑定地址行,所以我手动添加了它(绑定地址 0.0.0.0)并且我授予用户访问权限'%'

When I connected I got the message "Authentication failed"

当我连接时,我收到消息“身份验证失败”

But it works well on localhost/command line

但它在本地主机/命令行上运行良好

回答by rbz

  1. Delete or comment the bind_addressparameter from the my.inifile.
  1. bind_addressmy.ini文件中删除或注释参数。

(The file name is different depend on the OS. On Linux my.ini is actually my.cnf located in directory /etc/mysql/)

(文件名因操作系统而异。在 Linux 上 my.ini 实际上是位于目录 /etc/mysql/ 中的 my.cnf)

  1. Restart the service.
  2. Create the rootuser (yes, a new userbecause what exists is 'root@localhost' which is local access only):

    CREATE USER 'root'@'%' IDENTIFIED BY '123';

  3. Give the privileges:

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

  1. 重新启动服务。
  2. 创建root用户(是的,一个新用户,因为存在的是'root@localhost',它只能是本地访问):

    CREATE USER 'root'@'%' IDENTIFIED BY '123';

  3. 给予特权:

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%';

For DBAuser, add WITH GRANT OPTIONat the end.

e.g. CREATE USER 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;

对于DBA用户,WITH GRANT OPTION在最后添加。

例如 CREATE USER 'root'@'%' IDENTIFIED BY '123' WITH GRANT OPTION;



Because it does not work CREATE with GRANT?

因为它不适用于CREATE 与 GRANT

MySQL 8can no longer create a user with GRANT, so there is an error in IDENTIFIED BY '123'if you try to use it with GRANT, which is the most common error.

MySQL 8无法再创建用户 with GRANT,因此IDENTIFIED BY '123'如果您尝试将其与 一起使用GRANT,则会出现错误,这是最常见的错误。

回答by Milan

For MySQL 8 open the mysqld.cnf file

对于 MySQL 8,打开 mysqld.cnf 文件

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

And modify or add the bind-addressoption:

并修改或添加bind-address选项:

[mysqld]
bind-address = 0.0.0.0

Restart the mysqlserver

重启mysql服务器

sudo service mysql restart