2011-08-21 164 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

這不回答這個問題,你的代碼沒有解釋 - 這個問題已經被接受了。 –

相關問題