Revoke privileges

Asked

Viewed 2,172 times

5

I have a database and I’m trying to make sure that only my user has access to this base. ie no one else can open, search, delete anything. I’m using the following syntax:

GRANT USAGE ON batabase.* TO 'fabricio'@'%'; FLUSH PRIVILEGES;

But nothing has changed all users can still do anything.

1 answer

5


To revoke privileges you need to use the REVOKE. GRANT serves only to give privileges. The fact that you give privileges to a user does not automatically revoke anyone’s privilege. This way:

REVOKE ALL PRIVILEGES, GRANT OPTION FROM usuario1, usuario2

You can list all users separated by comma. I think the default user names you know: 'outrousuario'@'%'

For a specific database:

REVOKE ALL PRIVILEGES ON banco.* FROM usuario1, usuario2

Remembering that you only need to remove privileges from users who have them. If they have never received privileges they no longer get access.

Obviously you need to have privilege to do this.

To confirm the privileges configured for each user use:

SHOW GRANTS FOR usuario

To list the privileges of all users:

SHOW GRANTS FOR '%'@'%'

or

SELECT sql_grants FROM common_schema.sql_show_grants

As additional information it is possible to simplify the withdrawal of privileges of all users:

REVOKE ALL PRIVILEGES ON banco.* FROM '%'@'%'

Obviously if you need a specific user to have access you should give the privileges to him:

GRANT USAGE ON banco.* TO 'usuario'@'%'

After finishing the whole process it may be interesting to use FLUSH PRIVILEGES to guarantee the new status immediately.

It is obvious that it is not possible to revoke privileges that the user does not have in that host.

I put in the Github for future reference.

  • REVOKE ALL PRIVILEGES ON BdAlunos.* FROM 'root'@'%' just paste this into Mysql. If you have other users just repeat the process for each of them. There are other ways to do this, in simpler thesis, but I think you’ll get confused.

  • gave the following error Error Code: 1141. There is no such Grant defined for user 'root' on host '%'

  • Probably because this user has no privileges in this database. I suggest you read the manual and understand the whole process, all the implications. The answer was given. This website is support for using software, it is a website questions and objective answers. As you are having very basic difficulties understanding every step of the process is not even that complicated, but it is more than you seem to be able to handle, I strongly suggest you hire a professional to do these things for you. You can keep asking here but the questions need to have a focus.

  • I got mustache. Apparently it seems a simple doubt, translating well to the letter the error msg is saying that the root user does not have permission, but rather it has global permission. The solution would be to delete the root user, but, and if the client has a mysql application running, then I will screw BD gift from it.

  • just to make the debate worse see the syntax REVOKE ALL PRIVILEGES ON . FROM 'root'@'localhost'; This worked it accepted, but I can not restrict, I would like only the user had access to Bdalunos.

  • 1

    No, the error message says that there is no definition of privilege for the user root, who doesn’t need to take privilege away because he doesn’t have it anymore. Have the privileges listed as shown in the reply to see all existing privileges. The error does not say that the operation was denied. It just can’t be realized because it doesn’t make sense.

Show 1 more comment

Browser other questions tagged

You are not signed in. Login or sign up in order to post.