Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
582 views
in Technique[技术] by (71.8m points)

mysql - 授予**所有**数据库权限(Grant **all** privileges on database)

I've created database, for example 'mydb'.

(我创建了数据库,例如'mydb'。)

CREATE DATABASE mydb CHARACTER SET utf8 COLLATE utf8_bin;
CREATE USER 'myuser'@'%' IDENTIFIED BY PASSWORD '*HASH';
GRANT ALL ON mydb.* TO 'myuser'@'%';
GRANT ALL ON mydb TO 'myuser'@'%';
GRANT CREATE ON mydb TO 'myuser'@'%';
FLUSH PRIVILEGES;

Now i can login to database from everywhere, but can't create tables.

(现在我可以从任何地方登录到数据库,但无法创建表。)

How to grant all privileges on that database and (in the future) tables.

(如何授予该数据库和(将来)表的所有权限。)

I can't create tables in 'mydb' database.

(我无法在'mydb'数据库中创建表。)

I always get:

(我总是得到:)

CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);
ERROR 1142 (42000): CREATE command denied to user 'myuser'@'...' for table 't'
  ask by marioosh translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'%' WITH GRANT OPTION;

This is how I create my "Super User" privileges (although I would normally specify a host).

(这就是我创建“超级用户”权限的方式(虽然我通常会指定一个主机)。)

IMPORTANT NOTE (重要的提示)

While this answer can solve the problem of access, WITH GRANT OPTION creates a MySQL user that can edit the permissions of other users .

(虽然这个答案可以解决访问问题,但WITH GRANT OPTION创建了一个可以编辑其他用户权限的 MySQL 用户 。)

The GRANT OPTION privilege enables you to give to other users or remove from other users those privileges that you yourself possess.

(GRANT OPTION权限使您可以向其他用户提供或从其他用户中删除您自己拥有的权限。)

For security reasons, you should not use this type of user account for any process that the public will have access to (ie a website).

(出于安全原因,您不应将此类型的用户帐户用于公众可以访问的任何进程(即网站)。)

It is recommended that you create a user with only database privileges for that kind of use.

(建议您创建仅具有此类用途的数据库权限的用户 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...