场景:在kali中使用python中pymysql对Mariadb进行连接,在整个过程中配置全部正确,但是就是无法进行连接,提示结果如下:
Access denied for user 'root'@'localhost'
解决办法:进入数据库中,将默认密码进行修改执行以下语句:
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456'
连接测试函数:
import pymysqldef connect_to_mariadb():try:connection = pymysql.connect(host='localhost',user='root',password='123456',database='mysql',charset='utf8mb4',cursorclass=pymysql.cursors.DictCursor)print("成功连接到MariaDB!")return connectionexcept pymysql.Error as e:print(f"连接失败:{e}")# 调用函数进行连接
connection = connect_to_mariadb()
解决成功!