[英]How to connect database inside the cPanel using Python?
I would like to connect inside the database of cPanel using Python and insert some new data. 我想使用Python连接cPanel数据库并插入一些新数据。 I can write SQL and Python code to do the insertion. 我可以编写SQL和Python代码来进行插入。 However, but don't know how to connect with cPanel. 但是,但不知道如何与cPanel连接。
I have the website address (say, www.myuscanadahouse.com), cPanel username, cPanel password and database name inside the phpMyAdmin in the cPanel. 我在cPanel中的phpMyAdmin中有网站地址(例如,www.myuscanadahouse.com),cPanel用户名,cPanel密码和数据库名称。 Some tutorial or starting code in Python will be helpful. Python中的一些教程或启动代码会很有帮助。 I've seen this page https://pypi.python.org/pypi/pycpanel/0.1.2#id6 , but I wasn't able to make it work here. 我已经看过这个页面https://pypi.python.org/pypi/pycpanel/0.1.2#id6 ,但我无法在这里工作。
I get the following error while connecting with the MySQL database: 连接MySQL数据库时出现以下错误:
_mysql_exceptions.OperationalError: (1045, "Access denied for user'buildersa'@'47.124.85.71' (using password: YES)")
If you have a connection error, it's likely MySQL is bound to localhost. 如果您遇到连接错误,则可能是MySQL绑定到localhost。 Assuming you're using a Linux server: 假设您使用的是Linux服务器:
On your remote machine, edit /etc/mysql/my.cnf
在远程计算机上,编辑/etc/mysql/my.cnf
Find bind-address=127.0.0.1
, edit it to bind-address=0.0.0.0
, or just comment out. 找到bind-address=127.0.0.1
,将其编辑为bind-address=0.0.0.0
,或者只注释掉。
Restart MySQL 重启MySQL
service mysql restart
reference: stackoverflow & digitalocean reference: stackoverflow & digitalocean
If you will have an authentication error, connect to your MySQL (via ssh terminal) and make new user with grand privileges. 如果您将遇到身份验证错误,请连接到您的MySQL(通过ssh终端)并使用具有超级权限的新用户。
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'a_pass';
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'localhost' WITH GRANT OPTION;
CREATE USER 'new_user'@'%' IDENTIFIED BY 'a_pass';
GRANT ALL PRIVILEGES ON *.* TO 'new_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Then it's not a bad idea to restart MySQL again: 然后再次重启MySQL并不是一个坏主意:
service mysql restart
and try again with your new user credentials 并使用您的新用户凭据重试
reference DigitalOcean 参考DigitalOcean
Hope I helped, Good Luck 希望我帮助,祝你好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.