Mysql Create a database for a single user

Asked

Viewed 521 times

2

I want to create a database where only one user can access the information. Although there are already users created on the server, but only the user I create has to be the only one to have access to a certain database. I’m only able to do the reverse "create user for a single database". I am using this syntax to create the database, the user and their permission:

CREATE DATABASE test
  DEFAULT CHARACTER SET utf8
  DEFAULT COLLATE utf8_general_ci;

CREATE USER 'root'@'%' IDENTIFIED BY 'testing';
 GRANT ALL ON test.* TO 'root'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;
  • Your question begets conflict when you say that I’m only able to do the reverse "create user for a single database. But after all, what you need?

  • Take a look at the documentation using revoke to revoke other users' permissions. Mysql Doc I hope it helps.

  • @durtto when I said "Being able to do the Reverse" I meant creating a user with permissions in all databases. and I need a database where a user has permission only.

1 answer

0

An example CREATE USER 'usuario'@'localhost' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON * . * TO 'usuario'@'localhost';

After assigning everything, run the command FLUSH PRIVILEGES; to reload the privileges

If only one must have access permission, you can revoke the privileges of others or delete others as they will not have access

REVOKE [tipo de permissão] ON [nome da base de dados].[nome da tabela] FROM ‘[nome do usuário]’@‘localhost’;

or

DROP USER ‘demo’@‘localhost’;

Browser other questions tagged

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