简体   繁体   English

如何在python中修复此错误“与MySQL数据库的连接错误”

[英]How to fix this error “Connection Error with MySQL database” in python

I an setting up the connection with the MySQL server . 我设置了与MySQL服务器的连接。 This is the code I wrote and got the errors: 这是我写的代码并得到了错误:

import mysql.connector as mysql


def user_registration():
     connection_to_mysql = mysql.connect(host='localhost', user='root',
  passwd='aWais$777')

在此输入图像描述

尝试使用password而不是passwd ,并确保指定database

Please first trying with double quotes ie " " with password parameter passing. 请首先尝试使用双引号,即使用密码参数传递“”。 If not success then trying double quotes with all passing parameter ie host, user and password. 如果没有成功,则尝试使用所有传递参数的双引号,即主机,用户和密码。

Because of passwd field contains this symbol '$' that's why not accepting. 由于passwd字段包含此符号'$',这就是为什么不接受。

For more info visit check this code: https://www.w3schools.com/python/python_mysql_getstarted.asp 有关详细信息,请访问以下代码: https//www.w3schools.com/python/python_mysql_getstarted.asp

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="yourusername",
  passwd="yourpassword"
)

print(mydb)

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

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