简体   繁体   English

无法使用python连接到cpanel中的MySQL数据库

[英]Can't connect to MySQL database in cpanel using python

I want to connect the database(mysql) in cpanel using python. 我想使用python在cpanel连接数据库(mysql)。 But I don't know how to connect with cpanel using python. 但我不知道如何使用python与cpanel连接。

I've tried with the following code using pymysql module in python: 我已经尝试在python中使用pymysql模块使用以下代码:

import pymysql
pymysql.connect("ipaddress","user","password","database_name")

I get the following error while connecting to mysql: 连接到mysql时出现以下错误:

OperationalError: (1045, "Access denied for user 'username'@'DELL' (using password: YES)") OperationalError:(1045,“拒绝访问用户'username'@'DELL'(使用密码:是)”)

Seems like you do no have the appropriate permissions for the user. 似乎您没有该用户的适当权限。

  • First of all connect to MySQL with the root user and GRANT the desired user to the database. 首先,与连接到MySQL root用户和GRANT所需的用户到数据库。

  • Depending on what permissions the user needs eg: 根据用户需要的权限,例如:

    GRANT SELECT, INSERT, UPDATE ON database_name.* TO 'username'@'database_name' identified by 'password';

    or GRANT all privileges with: GRANT所有权限有:

    GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'database_name' identified by 'password';

  • Then save changes by using FLUSH PRIVILEGES; 然后使用FLUSH PRIVILEGES;保存更改FLUSH PRIVILEGES;

  • Try to connect again 尝试重新连接

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

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