开发者

How can I create a MySQL-database

I tried to create a database by the following command:

mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
-> CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
-> EXECUTE,CREATE VIEW,EVENT,TRIGGER
-> ON {projekti_db}.*
-> TO '{asiakas}'@'localhost';

and got the following error message

    ERROR 1064 (42000): 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 '{projekti_db}.*
    TO '{asiakas}'@'localhost'' at line 4

I ha开发者_JS百科ve MySQL 5.1.37. What am I doing wrong?


You are trying to assign roles to a user on a certain database. To create a database, use

CREATE DATABASE NAME;


That syntax doesn't create a database, it grants db privileges to a user.

To create a database, you'd use:

CREATE DATABASE projekti_db;

See here for a quick cheat sheet for MySQL.


#
# First create the Database
#
CREATE DATABASE projekti_db;

#
# Then Create the User that will access that database
#

GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,ALTER,INDEX,DROP,
CREATE TEMPORARY TABLES,SHOW VIEW,CREATE ROUTINE,ALTER ROUTINE,
EXECUTE,CREATE VIEW,EVENT,TRIGGER 
ON projekti_db.* 
TO 'asiakas'@'localhost';

#
# Now verify that the user asiaskas can access the projekti_db only from localhost
#
SHOW GRANTS FOR 'asiakas'@'localhost';

Give it a Try !!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜