简体   繁体   English

允许远程访问MySQL服务器(Windows | PyMySQL)

[英]Allowing Remote Access to a MySQL Server (Windows | PyMySQL)

I am creating a python tkinter application that will run on different computers all on one wifi network. 我正在创建一个python tkinter应用程序,它将在一个wifi网络上的所有不同计算机上运行。 Those computers should, through the tkinter app, communicate simultaneously with a database server hosted by a windows computer. 这些计算机应通过tkinter应用程序与Windows计算机托管的数据库服务器同时通信。 I have chosen MySQL and PyMySQL to accomplish these tasks. 我选择了MySQL和PyMySQL来完成这些任务。 I have experience with tkinter, but MySQL and networking in general are largely foreign to me. 我有tkinter的经验,但是MySQL和网络通常对我来说是陌生的。

I have downloaded and configured all the relevant MySQL software (Server, Router, Workbench, etc.) and created a database called comptool with a single table competitors . 我已经下载并配置了所有相关的MySQL软件(服务器,路由器,工作台等),并创建了一个名为comptool的数据库, comptool包含一个表competitors The server runs on localhost and port 3306. From the host computer, the tkinter app can interact with the database fine. 服务器在localhost和端口3306上运行。从主机上,tkinter应用程序可以与数据库进行交互。 From any other computer, I receive the following error when attempting to connect: 在任何其他计算机上,尝试连接时收到以下错误:

pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([WinError 10061] No connection could be made because the target machine actively refused it)")

With some searching I found many answers describing a MySQLInstanceConfig.exe file or a bind-address value in a my.cnf file. 通过一些搜索,我找到了许多描述MySQLInstanceConfig.exe文件或my.cnf文件中的bind-address值的答案。 The MySQLInstanceConfig.exe file does not appear to exist in MySQL 8.0, I have been unable to find a my.cnf file anywhere in Windows (I suspect this might be a Linux exclusive). MySQLInstanceConfig.exe文件似乎在MySQL 8.0中不存在,我一直无法在Windows中的任何地方找到my.cnf文件(我怀疑这可能是Linux专有的)。

There are also many mentions of specific privilege granting to the relevant database user, but all my attempts at privilege granting through the MySQL command line have returned syntax errors. 还提到了对相关数据库用户的特定特权授予,但是我通过My​​SQL命令行进行特权授予的所有尝试均返回了语法错误。 I use the following line (and variations of it): 我使用以下行(及其变体):

GRANT ALL ON comptool.* TO 'testuser'@'%' IDENTIFIED BY 'pass';

But I always receive the same error: 但是我总是收到相同的错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IDENTIFIED BY 'pass'' at line 1

Apart from any direct help, I am also curious as to why the hell there isn't simply a checkbox I can click in Workbench that allows remote access. 除了任何直接帮助之外,我还很好奇为什么为什么在Workbench中没有一个可以单击以允许远程访问的简单复选框。

Thanks. 谢谢。

Try 尝试

GRANT ALL PRIVILEGES ON database_name.* TO 'testuser'@'localhost' IDENTIFIED BY 'pass';

Then 然后

FLUSH PRIVILEGES;

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM