Mac系统sqlalchemy如何连接mysql数据库详解
Base = declarative_base()
class User(Base):
# 表的名字:
tablename = 'user'
# 表的结构:
id = Column(String(20), primary_key=True)
name = Column(String(20))
engine = create_engine('mysql+mysqlconnector://root:zhangqi310@localhost:3306/test')
DBSession = sessionmaker(bind=engine)
session = DBSession()
new_user = User(id='5', name='Q')
session.add(new_user)
session.commit()
session.close()
session = DBSession()
user = session.query(User).filter(User.id=='5').one()
print('type:', type(user))
print('name:', user.name)
session.close()
#修改加密方式
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported以及不知道如何再次修改mysql加密方式,把
本人在mac系统中向使用sqlalchemy链接mysql数据库,看遍了网上的教程,使遍了所有方法,依旧存在问题,下面是我使用github上一位博客写的源码进行运转,但是最后报错NotSupportedError: Authentication plugin 'caching_sha2_password' is not supported,随后也是查了很多相关的解决方案,发现需要修改mysql的加密方式,改成native password,但发现进不去mysql数据库了
mysqlalchemy连接mysql数据库,本人高二,在计算机方面有些不清楚的不熟练的地方,希望能得到master的解决!Thanks!
执行下面语句,将SQL支持远程访问试试
update user set host='%' where user='root';
flush privileges;
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!