<?php //open connection$con = mysql_connect("localhost","test","1234");//judge if successsif(!$con){ dir("Unable to connect to mysql" . mysql_error());}//create database name my_db//mysql_query("CREATE DATABASE my_db",$con))if(mysql_query("CREATE DATABASE my_db",$con)){ echo "Database created";}else { echo "Error creating database: " . mysql_error();}//close connectionmysql_close($con);?>
其中用户test为普通用户,因此无法创建数据库my_db,错误信息为 Access denied for user 'test'@'localhost' to database 'my_db'
把用户改为root就可以正常创建数据库文件了