CREATE USER 'tesrytss'@'%'//user name
IDENTIFIED VIA mysql_native_password USING '***';.//set pass
GRANT SELECT, INSERT, UPDATE, DELETE, FILE ON *.* TO 'tesrytss'@'%' // previlages and username and location
REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0; //other requerment
<?php
include("xmlapi.php");
$db_host = 'yourdomain.com';
$cpaneluser = 'your cpanel username';
$cpanelpass = 'your cpanel password';
$databasename = 'testdb';
$databaseuser = 'test'; // Warning: in most of cases this can't be longer than 8 characters
$databasepass = 'dbpass'; // Warning: be sure the password is strong enough, else the CPanel will reject it
$xmlapi = new xmlapi($db_host);
$xmlapi->password_auth("".$cpaneluser."","".$cpanelpass."");
$xmlapi->set_port(2082);
$xmlapi->set_debug(1);//output actions in the error log 1 for true and 0 false
$xmlapi->set_output('array');//set this for browser output
//create database
$createdb = $xmlapi->api1_query($cpaneluser, "Mysql", "adddb", array($databasename));
//create user
$usr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduser", array($databaseuser, $databasepass));
//add user
$addusr = $xmlapi->api1_query($cpaneluser, "Mysql", "adduserdb", array("".$cpaneluser."_".$databasename."", "".$cpaneluser."_".$databaseuser."", 'all'));
?>
mysql_connect('localhost','user',password);
mysql_query("CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';");
mysql_query("GRANT ALL ON db1.* TO 'username'@'localhost'");
mysql_query("CREATE DATABASE newdatabase");
mysql_close();
6条答案
按热度按时间q5lcpyga1#
我建议你用phpmyadmin。
您需要执行以下步骤:
打开phpmyadmin
转到管理部分
点击添加用户帐户
输入用户名和密码
设置权限
按[go]键
这是youtube上的全部内容[点击此处]
如果你想了解更多关于phpmyadmin的信息,请与官方联系
但是,如果有任何特殊的理由使用php,这里是sql
5kgi1eie2#
是的,因为所有这些操作都可以通过常规sql查询执行。
但是,我不想使用root用户的数据库连接运行php脚本。
nkcskrwz3#
p1iqtdky4#
如果您在cpanel上托管您的项目,那么
mysql_query
方法无法创建数据库、用户和授予权限。您必须使用cpanel的xmlapi。
从这里下载xmlapi.php,或者在google上搜索它。
这对我来说非常有效。
4dc9hkyq5#
打开php myadmin或mysql workbench转到查询窗口,然后运行下面的查询
myzjeezk6#
你可以这样做:
您可以查看关于grant和create user的mysql文档