在 WHM/cPanel 服务器上通过 PHP 以编程方式创建数据库
我想知道是否可以在 WHM/cPanel 服务器上从 PHP 创建新的数据库和用户。
I was wondering whether it is possible to create a new database and user, from PHP, on an WHM/cPanel server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,就是这样。
“mysql_create_db”函数在 cPanel 服务器上无法正常工作。
有一个解决方案,通过使用专有的 cPanel 函数,如下所示
http://USER:PASS@HOST:2082/frontend/SKIN/sql/adddb.html?db=DB
不过, 还有一个现成的脚本,可以在这里使用 http://www.zubrag .com/scripts/cpanel-database-creator.php
Ok, this is the thing.
'mysql_create_db' function does not work properly on cPanel servers.
There is a solution to this though, by using the proprietary cPanel function like so
http://USER:PASS@HOST:2082/frontend/SKIN/sql/adddb.html?db=DB
There is also a ready-made script that can be used here http://www.zubrag.com/scripts/cpanel-database-creator.php
对于控制面板:
For CPanel:
创建数据库:
或
http ://www.php.net/manual/en/function.mysql-create-db.php
创建MySQL用户:
您可以通过生成SQL并运行来创建用户帐户通过
mysql_query
(就像第一个示例一样): http://dev.mysql.com/doc/refman/5.1/en/adding-users.htmlTo create a DB:
or
http://www.php.net/manual/en/function.mysql-create-db.php
To create a MySQL user:
You can create user account by generating the SQL and running it through
mysql_query
(just like the first example): http://dev.mysql.com/doc/refman/5.1/en/adding-users.html只要您用来连接数据库的用户具有 MySQL 中定义的适当权限,这就不成问题。
要创建数据库,用户需要 CREATE 权限 (删除它们将是 DROP 权限),要创建用户,您需要拥有 创建用户权限。您可能还需要 GRANT OPTION 权限 能够向其他用户授予权限。
因此,只要您可以通过 WHM/cPanel 创建的数据库用户拥有这些权限,就应该没问题。
As long as the user you use to connect to the database has the appropriate privileges defined in MySQL this shouldn't be a problem.
To create databases the user needs the CREATE privilege (to drop them that would be DROP privilege), to create user(s) you need to have the CREATE USER privilege. You also might need the GRANT OPTION privilege to be able to grant privileges to other users.
So as long as the DB user(s) you can create through WHM/cPanel have these privileges, you should be ok.