2011-08-21 259 views
1

我不断收到此错误,我不确定为什么这不起作用。无法在服务器上使用PHP创建MySQL数据库?

我想用PHP创建一个数据库,它返回以下错误:

Error creating database: Access denied for user 'scriptcooke'@'10.%' to database 'my_db' 

我相信我有正确的凭据,但到底是什么@ 10%,甚至是什么意思?

注:我试图使用w3schools code example这里:

<?php 
$con = mysql_connect("localhost","peter","abc123"); 
if (!$con) 
    { 
    die('Could not connect: ' . mysql_error()); 
    } 

if (mysql_query("CREATE DATABASE my_db",$con)) 
    { 
    echo "Database created"; 
    } 
else 
    { 
    echo "Error creating database: " . mysql_error(); 
    } 

mysql_close($con); 
?> 
+0

还有CREATE TABLE操作的mysql帐户权限。该帐户没有他们。 – mario

回答

1

@10.%是在用户定义的源主机领域。

问题是:您没有创建新数据库的权限。您正在使用的用户只能使用他自己的数据库;

0

10.指子网的IP的第一个八位字节。在英语中,它指的是用户正在连接的网络“部分”。试试@localhost或@。*

0
 <?php 
     //Create simple connection with no any error. 
     //connect with no password but. 
     $con=mysql_connect("localhost","root",""); 
     mysql_select_db("my_db") or die(mysql_error()); 
     //Retrieve all the data from the "example" table 
     $result = mysql_query("select * from contact LIMIT 0, 30 ")or 
     die(mysql_error()); 

     // store the record of the "example" table into $row 
     $row = mysql_fetch_array($result); 

     // Print out the contents of the entry  
     echo "Name: ".$row['Name']; 
     echo "Email: ".$row['Email']; 
     mysql_close($con); 
     ?> 
0

首先你需要在mysql中创建数据库的权限。如果你是用户,那么你可以创建mysql数据库。所以首先你必须检查数据库是否连接。 用于创建数据库的PHP代码是:

<?php 
    $con=mysql_connect('localhost','root',''); 
    if($con) 
    { 
    $query=mysql_query('create database new') or die(mysql_error()); 
    $qu=mysql_query('use new'); 
    if($query) 
    { 
     echo'Database is created'; 
     } 
    else 
    { 
    echo'Database is not created'; 
    } 
    } 
    else 
    { 
    echo'The database is not connected'; 
    } 
?> 
-2
  1. connect_error){ 模具( “连接失败” $ conn-> connect_error); } //创建数据库$ sql =“CREATE DATABASE myDB”;如果 ($ conn-> query($ sql)=== TRUE){ echo“Database created successfully”; } else { echo“创建数据库时出错:”。 $ conn->的错误; } $ conn-> close(); ?>
+0

这不回答这个问题,你的代码没有解释 - 这个问题已经被接受了。 –

相关问题