php脚本自动创建mysql数据库? [英] php script automatically creating mysql database?
问题描述
有没有人知道是否有一个脚本,会自动创建一个mysql数据库,而不必进入cpanel并手动创建数据库,用户名和密码?
does anyone know if there's a script out there that will create a mysql database automatically instead of having to go into cpanel and create a database, username and password manually?
感谢
推荐答案
您无法创建用户名和密码,除非您使用更高级别的用户登录。这通常是根。在使用具有足够权限的用户名和密码后,创建数据库很简单。
You cannot create a username and password unless you log in yourself with a user with a higher level. That's usually the root. Creating database is a breeze after using the username and password with sufficient privileges.
<?php
$dsn = $dsn = "mysql:host=localhost";
$pdo = new PDO($dsn,"root","");
//Creation of user "user_name"
$pdo->query("CREATE USER 'user_name'@'%' IDENTIFIED BY 'pass_word';");
//Creation of database "new_db"
$pdo->query("CREATE DATABASE `new_db`;");
//Adding all privileges on our newly created database
$pdo->query("GRANT ALL PRIVILEGES on `new_db`.* TO 'user_name'@'%';");
?>
在此脚本中,我假设您的root用户被称为root并且其密码为 ,如果不是这样,请将第4行匹配。
In this script, I assumed your root user is called "root" and its password is empty if that's not the case, change line 4 to match.
这篇关于php脚本自动创建mysql数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!