如何授予其他PC权限以将数据添加到我的计算机中MySQL.my数据库中 [英] How to give permission to other PC to add data to my database in MySQL.in my computer

查看:59
本文介绍了如何授予其他PC权限以将数据添加到我的计算机中MySQL.my数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里制作了一个python程序,我想将代码发送给我的朋友,他无法通过该程序向我的数据库添加值,有没有办法我可以允许他访问.

I made a python program here and i wanted to send the code to my friend and he was unable to add values through the program to my database, is there a way i can allow his access.

代码:

from tkinter import *
import mysql.connector as mysql

root = Tk()


def flush(*args):
    name = nme.get()
    phone = ph.get()
    emirate = e_id.get()
    con = mysql.connect(host='127.0.0.1', user='root', password='monkey123', database='NZ')
    c = con.cursor()
    c.execute("Insert into gliy VALUES ('"+name+"','"+str(phone)+"','"+str(emirate)+"')")

    c.execute('commit')

    con.close()
    e_1.delete(0, END)
    e_2.delete(0, END)
    e_3.delete(0, END)

nme= StringVar()
ph = IntVar()
e_id = IntVar()

label_1 = Label(root,text='Patient Name',fg='blue')
label_2 = Label(root,text='Phone number',fg='blue')
label_3 = Label(root,text='Emirates ID',fg='blue')

label_1.grid(row=0,column=0)
label_2.grid(row=1,column=0)
label_3.grid(row=2,column=0)

e_1 = Entry(root,borderwidth=2,textvariable=nme)
e_2 = Entry(root,borderwidth=2,textvariable=ph)
e_3 = Entry(root,borderwidth=2,textvariable=e_id)

e_1.grid(row=0,column=1,ipady=10,padx=10,pady=10)
e_2.grid(row=1,column=1,ipady=10,padx=10,pady=10)
e_3.grid(row=2,column=1,ipady=10,padx=10,pady=10)

B_1 = Button(root,text='ENTER',command =flush)
B_1.grid(row=4,column=1)

root.mainloop()

错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\network.py", line 509, in open_connection
    self.sock.connect(sockaddr)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in _call_
    return self.func(*args)
  File "C:/Users/97513/AppData/Local/Programs/Python/Python38-32/new.py", line 14, in flush
    con = mysql.connect(host='127.0.0.1', user='root', password='monkey123', database='NZ')
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 95, in _init_
    self.connect(**kwargs)
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\abstracts.py", line 716, in connect
    self._open_connection()
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\connection.py", line 206, in _open_connection
    self._socket.open_connection()
  File "C:\Users\97513\AppData\Local\Programs\Python\Python38-32\lib\site-packages\mysql\connector\network.py", line 511, in open_connection
    raise errors.InterfaceError(
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (10061 No connection could be made because the target machine actively refused it)

推荐答案

之所以发生这种情况,是因为您在计算机上本地运行MySQL(通过使用 127.0.0.1 给出).换句话说,您有一个进程/程序(MySQL)在 only 计算机的后台运行.为了使您的朋友能够访问此数据库,您需要执行以下两项操作之一:

This is happening because you are running MySQL locally on your computer (as given by your use of 127.0.0.1). In other words, you have a process/program (MySQL) running in the background of only your computer. For your friend to have access to this database, you will need to either of two things:

  1. 将您的MySQL实例(在计算机上运行)公开.
    • 这有其局限性.如果您关闭计算机,或者无法访问互联网,那么您实际上正在与世界其他地方关闭MySQL实例.
    • 涉及端口转发和排序-这可能很麻烦.
  • Google:免费的mysql提供程序".您会发现一些结果,这些结果使您可以创建具有限制(通常是大小限制)的免费MySQL数据库.
  • 您将连接到 mysql://website.com:33060/path/to/your/database
  • ,而不是连接到 127.0.0.1 >

方法2是最简单的.您可以在线使用免费服务来创建您和您的朋友可以访问的MySQL服务器.

Method 2 is the easiest. You can use free services online to create a MySQL server that you and your friend can access.

这篇关于如何授予其他PC权限以将数据添加到我的计算机中MySQL.my数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆