我想知道這對你有多好。我當然希望這是未來的證明(並在一定程度上是安全的)。僅爲用戶添加CREATE和轉儲權限以保持一點安全。對於臨時文件 chmod 1777 /tmp
<?php
/* this is for a test website I was building */
$dbusername = "admin_user";
$dbuserpass = "secretPa$$";
$dbname="new_customer_DB"; //use a more unique name
$mysqli = new mysqli("localhost", $dbusername, $dbuserpass, "your_admin_db");
$sql = "CREATE DATABASE `".$dbname."` /*!DEFAULT CHARACTER SET utf8 */;";
if ($mysqli->query($sql)) {
printf("$dbname successfully created.\n");
}
// dump database from master db into newly created one.
// dbname and masterdb are important
$masterdb ="customer_db_template";
$olduser= $dbusername;
$file = tempnam("/tmp", "FOO");
$content= "[client]\n";
$content.= "user=$dbusername \n";
$content.= "password=$dbuserpass \n";
$content.= "host=localhost";
file_put_contents($file, $content);
print "<hr> ";
$cmd = "mysqldump --defaults-extra-file=$file --routines --opt $masterdb | mysql --defaults-extra-file=$file --host=localhost -C $dbname;";
print $cmd;
print "<pre>";
system($cmd );
unlink($file); //delete right away
mysqli::close ($mysqli);
print "</pre>";
?>
功率回答者
編輯權限:我怎麼辦?
是的,這是可能的。怎麼樣?這取決於你...... –
好,是的。您必須在代碼中重新創建您自己手動添加新用戶的所有內容。 –
@MarcB你可以給我一些提示嗎?我是否需要玩我的服務器數據庫?對新用戶享有特權? –