如何创建MySQL数据库

时间:2011-02-10 21:28:25

标签: mysql

我尝试通过以下命令创建数据库:

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';

并收到以下错误消息

    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

我有MySQL 5.1.37。我做错了什么?

3 个答案:

答案 0 :(得分:0)

您正尝试将角色分配给特定数据库上的用户。要创建数据库,请使用

CREATE DATABASE NAME;

答案 1 :(得分:0)

该语法不会创建数据库,它会向用户授予数据库权限。

要创建数据库,您可以使用:

CREATE DATABASE projekti_db;

See here for a quick cheat sheet for MySQL

答案 2 :(得分:-1)

#
# 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';

试一试!!!