2011-11-16 196 views
1

我一直在玩弄創建一個新用戶,我不斷收到此錯誤:MySQL的授予權限的用戶

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `testingUser' at line 3

和我的查詢是:

mysql_query(" 

GRANT USAGE ON *.* TO '$user'@'localhost' IDENTIFIED BY '$pass'; 

GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `$user\_database`.* TO '$user'@'localhost'; 

GRANT SELECT (Table_priv, Column_priv, Table_name, Db, User, Host) ON `mysql`.`tables_priv` TO '$user'@'localhost'; 

GRANT SELECT ON `mysql`.`host` TO '$user'@'localhost'; 

GRANT SELECT (Host, Create_priv, Shutdown_priv, Delete_priv, User, Process_priv, Reload_priv, Alter_priv, Super_priv, Grant_priv, Create_tmp_table_priv, Execute_priv, Repl_client_priv, Insert_priv, Repl_slave_priv, Lock_tables_priv, References_priv, Index_priv, File_priv, Drop_priv, Show_db_priv, Select_priv, Update_priv) ON `mysql`.`user` TO '$user'@'localhost'; 

GRANT SELECT ON `mysql`.`db` TO '$user'@'localhost';"); 
+2

'mysql_query'無法執行多個查詢 – Kru

回答

3

不能發出多在一個mysql_query()呼叫查詢。這是防止某些形式的SQL注入的安全限制。您必須在單獨的mysql_query()調用中發出每個授權查詢。

mysql_query("GRANT ..."); 
mysql_query("GRANT ..."); 
etc... 
+0

需要標記爲答案。我同意這個 –

+0

謝謝,這解決了我的問題 – 2kan