自动创建mysql数据库,php脚本自动创建mysql数据库?

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?

thanks

解决方案

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.

$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'@'%';");

?>

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值