Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql连接器在使用python连接器时出现语法错误_Python_Mysql_Mysql Error 1064_Mysql Connector_Mysql Connector Python - Fatal编程技术网

Mysql连接器在使用python连接器时出现语法错误

Mysql连接器在使用python连接器时出现语法错误,python,mysql,mysql-error-1064,mysql-connector,mysql-connector-python,Python,Mysql,Mysql Error 1064,Mysql Connector,Mysql Connector Python,因此,我用python制作了一个密码管理器,使用mysql存储数据。当我尝试使用mysql连接器创建表时,出现以下错误: 您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以获取第1行“”附近要使用的正确语法 我的完整代码是 import mysql.connector as mysql import tkinter as tk from simplecrypt import * def createusr(): global oo global pss

因此,我用python制作了一个密码管理器,使用mysql存储数据。当我尝试使用mysql连接器创建表时,出现以下错误:

您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以获取第1行“”附近要使用的正确语法

我的完整代码是

import mysql.connector as mysql
import tkinter as tk

from simplecrypt import *

def createusr():
    global oo
    global pss
    top1 = tk.Toplevel(root)
    top1.title('Create new user ')
    top1.geometry('480x360')
    oo = tk.StringVar()
    pss = tk.StringVar()
    userid = tk.Label(top1, text = 'Enter User ID: ')
    userid.place(relx = 0.09, rely = 0.1, relheight = 0.058, relwidth = 0.24)
    entrusr = tk.Entry(top1, bg = 'gray',  textvariable = id)
    entrusr.place(relx = 0.3, rely = 0.1, relheight = 0.058, relwidth = 0.24)
    pwd = tk.Label(top1, text = "enter password: ")
    pwd.place(relx = 0.08, rely = 0.18, relheight = 0.058, relwidth = 0.24)
    pwde = tk.Entry(top1, bg = 'gray',  textvariable = pss)
    pwde.place(relx = 0.3, rely = 0.18,relheight = 0.058, relwidth = 0.24)
    hnt = tk.Label(top1, text = "hint: ")
    hnt.place(relx = 0.15, rely = 0.33, relheight = 0.058, relwidth = 0.24)
    hnte = tk.Entry(top1, bg = 'gray')
    hnte.place(relx = 0.3, rely = 0.33, relheight = 0.058, relwidth = 0.24)
    createacc = tk.Button(top1, text = 'Create Account', font = 50, command = newacc)
    createacc.place(relx = 0.1, rely = 0.42, relheight = 0.058, relwidth = 0.24)


def settings():
    top3 = tk.Toplevel(root)
    top3.title('Settings')
    top3.geometry('480x360')
    url = tk.IntVar()
    #darkt = tk.IntVar()
    #lightt = tk.IntVar()
    ourl = tk.Checkbutton(top3, text = "open URL of service instantly", variable = url)
    ourl.pack()
    #theme = tk.Label(top3, text = 'Theme:')
    #theme.pack()
    #dark = tk.Checkbutton(top3, text = 'Dark', variable = darkt, command = reset(f = True))
    #dark.pack()
    #light = tk.Checkbutton(top3, text = 'Light', variable = lightt, command = reset)
    #light.pack()


def forgotT():
    top2 = tk.Toplevel(root)
    top2.title('recover password')
    top2.geometry('480x360')
    hint = tk.Label(top2)

def newacc():
    check = str("DROP TABLE IF EXISTS" + str(oo.get()))
    table = "CREATE TABLE {0}(SERVICE VARCHAR(100), USERNAME VARCHAR(100),PASSWORD VARCHAR(256))".format(str(oo.get()))
    cursor.execute(table)
    msql.close()




root = tk.Tk()
root.title('Cipher')
canvas = tk.Canvas(root, height=480, width=360)
canvas.pack()
msql = mysql.connect(user='root', password='7014403396', database='cipher')
cursor = msql.cursor()
coolimg = tk.PhotoImage(file='images-4.png')
settt = tk.PhotoImage(file='settings+icon-1320183238404656194_16.png')


img = tk.Label(root, image = coolimg)
img.place(relx = 0.3, rely = 0.07, relheight = 0.5, relwidth = 0.4)
Userid = tk.Label(root, text = 'User ID: ', width = 20)
Userid.place(relx = 0.2, rely = 0.6, relheight = 0.04, relwidth = 0.2)
passwd = tk.Label(root, text = 'Password: ', width = 20)
passwd.place(relx = 0.2, rely = 0.65, relheight = 0.04, relwidth = 0.2)
create = tk.Button(root, text = 'Create', font = 50, command = createusr)
create.place(relx = 0, rely = 0.9, relwidth = 0.3)
forgot = tk.Button(root, text = 'Forgot?', font = 50)
forgot.place(relx = 0.72 ,rely = 0.9, relwidth = 0.3)
usrent = tk.Entry(root, bg = 'gray')
usrent.place(relx = 0.37, rely = 0.6, relheight = 0.045, relwidth = 0.24)
psent = tk.Entry(root, bg = 'gray')
psent.place(relx = 0.37, rely = 0.65, relheight = 0.045, relwidth = 0.24)
sett = tk.Button(root, image = settt, command = settings)
sett.place(relx = 0.9, rely = 0.07, relheight = 0.05, relwidth = 0.05)
login = tk.Button(root, text = 'Log in', font = 50)
login.place(relx = 0.2, rely = 0.7, relheight = 0.05, relwidth = 0.48)

root.mainloop()
问题在于:

    def newacc():
        check = str("DROP TABLE IF EXISTS" + str(oo.get()))
        table = "CREATE TABLE {0}(SERVICE VARCHAR(100), USERNAME VARCHAR(100),PASSWORD VARCHAR(256))".format(str(oo.get()))
        cursor.execute(table)
        msql.close()
'''


你能帮忙吗?

check=str(“如果存在,请删除表”+str(oo.get())
在EXISTS关键字后面需要一个空格。

我猜是哪里出了问题

def newacc():
    check = "DROP TABLE IF EXISTS {}".format(oo.get()) 
    table = '''CREATE TABLE `{}`(
        `SERVICE` VARCHAR(100), 
        `USERNAME` VARCHAR(100),
        `PASSWORD` VARCHAR(256))'''.format(oo.get())
    cursor.execute(table)
    msql.close()
请尝试一下,如果有任何错误,请告诉我


干杯

虽然我没有执行变量检查,但我正在执行表。这是什么错误?您确实缺少一个空格:
{0}(服务
应该是
{0}(服务
。如果这还不能解决问题,你应该在格式化后打印出
变量,并仔细检查它。@克里斯,实际上我不认为问题出在空格上。我确实注意到当它被指出时,但程序即使在解决空格后也无法工作。@CoolCloud,你能告诉我问题出在哪里吗你?@avisharma试着用反勾号(`)来表示密码,语法实际上是错误的,试着用多行代码在这里生成一个表,
{0}
意味着什么?你实际上在
check
变量中连接了两个字符串。并且试着把它变成
{}
{0}
是有效的python:它引用了
格式中的参数顺序。在这种情况下,它与
{}
相同,因为
格式
@chris oh只有一个参数,我明白了,那么他可能应该尝试使用多行字符串并尝试使用反勾(`)指定列名和表名,因为我相信
密码
是一个MySQL函数。@Cloud--ya,你说的空间不是一个问题是对的。对密码使用反勾号似乎是有可能的!如果不是这样,它必须是
oo.get()
返回的任何内容。