【问题标题】:How to set up sqlite to be local server (on lan)如何将 sqlite 设置为本地服务器(在局域网上)
【发布时间】:2021-06-15 04:09:35
【问题描述】:

当前情况:我有一个 GUI 程序(由 python 编写),它使用存储在我计算机上的 sqlite 数据。

愿望清单:我想要一台服务器计算机来定位 sqlite 数据(DATA A1)(需要 CRUD 操作)和另外十台使用 GUI 程序(由 python 编写)的客户端计算机,它们与 sqlite 数据(DATA A1)连接局域网。

我不知道如何设置这个程序和服务器以及我需要了解更多信息。

当前在商店中检查产品的示例代码:

import sqlite3
from tkinter import *
from tkinter import ttk

GUI = Tk()
GUI.geometry('1280x720')

def connect_product_data():
    global conn
    global c
    conn = sqlite3.connect('A1.db')
    c = conn.cursor()

def pull_product_data():
    global sqlselectdata
    connect_product_data()
    with conn:
        c.execute("""SELECT * FROM PDLIST""",
            )
    sqlselectdata = c.fetchall()
    conn.commit()
    return sqlselectdata

tree_view_frame = Frame(GUI)
tree_view_frame.pack()
tree_scroll = Scrollbar(tree_view_frame)
tree_scroll.pack(side = RIGHT, fill = Y)

header = ['Part No.', 'Name', 'Price']
hdsize = [70,250,70]
aanchor = [W,W,E]
global product_table
product_table = ttk.Treeview(tree_view_frame, columns = header, show = 'headings', height = 20, yscrollcommand=tree_scroll.set, selectmode="extended")
def treeview_sort_column(product_table, col, reverse):
    l = [(product_table.set(k, col), k) for k in product_table.get_children('')]
    try:
        l.sort(key=lambda t: float(t[0].replace(",","")), reverse=reverse)
    except:
        l.sort(reverse=reverse)
    for index, (val, k) in enumerate(l):
        product_table.move(k, '', index)
    product_table.heading(col, command=lambda _col=col: treeview_sort_column(product_table, _col, not reverse))
for col in header:
    product_table.heading(col, text=col,command=lambda _col=col: treeview_sort_column(product_table, _col, False))
product_table.pack()
tree_scroll.config(command = product_table.yview)
for h,s,a in zip(header, hdsize, aanchor):
    product_table.heading(h, text = h)
    product_table.column(h,width = s, anchor = a)

def check_Product():
    A1data = pull_product_data()
    if len(A1data)>0:
        for v in A1data:
            product_table.insert('', 'end', value = (v[0],v[1],v[2]))

B_check_product = ttk.Button(GUI, text = "Add Product", width = 15, command = check_Product)
B_check_product.pack()

GUI.mainloop()

将 sqlite3 更改为 MySQL:

def connect_product_data():
    global mc
    global conn
    conn = mysql.connector.connect(
        host="localhost",
        user="root",
        password="123456789",
        database="mydatabase"
    )
    mc = conn.cursor()

def pull_product_data():
    global sqlselectdata
    connect_product_data()
    mc.execute("SELECT * FROM customers")
    sqlselectdata = mc.fetchall()
    conn.commit()
    return sqlselectdata

【问题讨论】:

    标签: python sql sqlite


    【解决方案1】:

    不要那样做。 Sqlite 是一个简单的内存中单进程数据库。如果您需要数据库服务器,请使用数据库服务器。有很多选择。

    【讨论】:

    • 能否请您推荐一款适合我申请的:一台服务器计算机,十个客户端和CRUD操作(如果可能,免费程序)。
    • 如果你想要 SQL,主要的选择是 MySQL 和 Postgres。两者都是开源的、得到很好的支持和生产质量。
    • 我已经在尝试使用 MySQL。下一步我应该做什么来设置服务器?
    • 谷歌。读。答案取决于您使用的操作系统,但有很好的教程可供使用。
    猜你喜欢
    • 2016-07-21
    • 2020-12-14
    • 2023-03-28
    • 1970-01-01
    • 2011-10-20
    • 1970-01-01
    • 2016-04-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多