简体   繁体   English

远程 mysql 连接无法建立/主机不允许

[英]Remote mysql connection can not be established / host is not allowed

  • I have laravel web application and mysql running under same ip.我有 laravel web 应用程序和 mysql 在同一 Z957B527BCFBAD2E80F58D2068393 下运行。
  • web is encrypted with ssl certificate web 使用 ssl 证书加密
  • firewall is ufw and ufw is set up as following防火墙是ufw,ufw设置如下
    To Action From -- ------ ---- Nginx Full ALLOW Anywhere OpenSSH ALLOW Anywhere 443/tcp ALLOW Anywhere 3306/tcp ALLOW Anywhere 3306 ALLOW Anywhere Nginx Full (v6) ALLOW Anywhere (v6) OpenSSH (v6) ALLOW Anywhere (v6) 443/tcp (v6) ALLOW Anywhere (v6) 3306/tcp (v6) ALLOW Anywhere (v6) 3306 (v6) ALLOW Anywhere (v6)
  • namp check from remote machine shows that port is open远程机器的namp检查显示端口已打开
     nmap 161.54.46.221 Starting Nmap 7.80 ( https://nmap.org ) at 2022-09-07 07:52 UTC Nmap scan report for static.221.46.54.161.clients.your-server.de (161.54.46.221) Host is up (0.0045s latency). Not shown: 996 filtered ports. PORT STATE SERVICE 22/tcp open ssh 80/tcp open http 443/tcp open https 3306/tcp open mysql Nmap done: 1 IP address (1 host up) scanned in 4.77 seconds
  • mysql connection locally using ip as host is also working mysql 本地连接使用 ip 作为主机也在工作
    >:~$ mysql -u readUser -h 161.54.46.221 -p Enter password: Welcome to the MySQL monitor. Commands end with; or \g. Your MySQL connection id is 74 Server version: 8.0.30-0ubuntu0.20.04.2 (Ubuntu) Copyright (c) 2000, 2022, Oracle and/or its affiliates. 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>
  • In mysql setting /etc/mysql/mysql.conf.d/mysqld.cnf, bind address is also set up correctly在mysql设置/etc/mysql/mysql.conf.d/mysqld.cnf中,绑定地址也设置正确
  • My setting with \s command is given below我的 \s 命令设置如下
    Connection id: 25 Current database: Current user: sharma@static.221.48.54.161.clients.your-server.de SSL: Cipher in use is TLS_AES_256_GCM_SHA384 Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 8.0.30-0ubuntu0.20.04.2 (Ubuntu) Protocol version: 10 Connection: 161.54.48.221 via TCP/IP Server characterset: utf8mb4 Db characterset: utf8mb4 Client characterset: utf8mb4 Conn. characterset: utf8mb4 TCP port: 3306 Binary data as: Hexadecimal Uptime: 29 min 2 sec Threads: 4 Questions: 5857 Slow queries: 0 Opens: 180 Flush tables: 3 Open tables: 99 Queries per second avg: 3.362

-I can connect mysql server with telnet locally -我可以在本地通过telnet连接mysql服务器

Trying 161.54.46.221...
Connected to 161.54.46.221.
Escape character is '^]'.
[
 u▒k#^oI_~(Bh?caching_sha2_password
  • However If try to connect from remote to my sql server, the error is "host is not allowed to connect the mysql server".但是,如果尝试从远程连接到我的 sql 服务器,错误是“主机不允许连接 mysql 服务器”。
  • For example, If I try to connect form a remote server then it says host is not allowed.例如,如果我尝试从远程服务器连接,那么它说主机是不允许的。 What can be the reason?可能是什么原因?
     telnet 161.54.48.221 3306 Trying 161.54.48.221... Connected to 161.54.48.221. Escape character is '^]'. @Host 'bernstein.store' is not allowed to connect to this MySQL serverConnection closed by foreign host.

Could you please help regarding this problem?你能帮忙解决这个问题吗? I would be thankful我会很感激

  • I got the answer now.我现在得到了答案。 The way how I went for remote connection process was all correct.我进行远程连接过程的方式都是正确的。 It was actually easy.这实际上很容易。 But I spent a huge amount time on it for such a small thing但是为了这么一件小事我花了很多时间
  • I set host as the ip address in the user table我在user表中设置host为ip地址
  • The user was saved as 'readUser'@'161.54.46.221'.用户被保存为'readUser'@'161.54.46.221'。 What I just had to do is to save user as 'readUser'@'%'.我只需要将用户保存为'readUser'@'%'。 So use the following command to change your host as following and then all should work now.因此,使用以下命令将您的主机更改如下,然后一切都应该工作了。
     USE mysql; Update user set host='%' where user='readUser'; FLUSH PRIVILEGES;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查mysql与远程主机的连接 - Check mysql connection to remote host 如何建立与MySql Server的连接? - How can I established connection to MySql Server? 未与localhost建立MySQL连接 - Mysql connection is not established with localhost mysql_connect在远程主机连接上返回“无法通过套接字连接到本地MySQL服务器”? - mysql_connect returning “Can't connect to local MySQL server through socket” on remote host connection? Host...not allowed error in ODBC connection, while connecting to an online MySQL 数据库 - Host...not allowed error in ODBC connection, while connecting to an online MySQL database C# MySql 错误:已建立的连接被主机中的软件中止 - C# MySql error: An established connection was aborted by the software in your host machine Python 到 MySQL 错误:[WinError 10053] 已建立的连接被主机中的软件中止 - Python to MySQL error: [WinError 10053] An established connection was aborted by the software in your host machine 通过PHP而不是通过MySQL Workbench拒绝与远程MySQL主机的连接 - Connection denied to remote MySQL host through PHP but not through MySQL Workbench 在远程主机上查询期间失去与MySQL服务器的连接 - Lost connection to MySQL server during query on remote host Java SSH连接到mysql访问localhost而不是远程主机 - java SSH connection to mysql accessing localhost instead of remote host
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM