Problem creating user

1

I'm trying to create a user using this grant command:

GRANT ALL ON usuario.* to usuario@localhost IDENTIFIED BY 'contrasena';

The problem is that it does not recognize the end of the quotes, so it recognizes that it has not finished executing. If I put other quotes so that it closes and executes it gives error.

    
asked by Jesus Redondo 14.04.2018 в 14:52
source

2 answers

3

As stated in the comment that I made this is giving permission to a user, which is not yet created, you must first create the user:

CREATE USER 'usuario'@'localhost' IDENTIFIED BY 'clave';

Try this to give you access to the dbTest database:

GRANT ALL PRIVILEGES ON dbPrueba.* To 'usuario'@'localhost';

Then, to reload the newly assigned permissions, execute:

FLUSH PRIVILEGES;

Example in a line:

CREATE USER 'usuario'@'localhost' IDENTIFIED BY 'clave'; GRANT ALL PRIVILEGES ON baseDatos.* To 'usuario'@'localhost' IDENTIFIED BY 'clave'; FLUSH PRIVILEGES;

Usage:

  
  • GRANT : This is the command used to create users and grant rights to databases, tables, etc.

  •   
  • ALL PRIVILEGES : This tells you that the user will have all the standard privileges. However, this does not include the privilege of using the GRANT command.

  •   
  • dbPrueba.* This MySQL instruction to apply these rights for use in the entire dbTest database. You can replace * with specific table names or save routines if you wish.

  •   
  • TO 'usuario'@'localhost' : Is the username of the user account you are creating. Note: you must have the single quotes there. 'localhost' tells MySQL what hosts the user can connect to. If you only want it from the same machine, use localhost

  •   
  • IDENTIFIED BY 'clave' : As you may have guessed, this sets the password for that user.

  •   

Update:

Check the permissions that the previous command issued for that user by executing the following command.

SHOW GRANTS FOR 'usuario'@'localhost'

In the comments, it tells me that although it is believed that it is not allowed to be accessed, try to create the user once logged as root

$ mysql -u root -p -e "grant all privileges on baseDatos.* to
'{usuario}'@'{localhost}' identified by '{clave}'; flush privileges;"

Ignore the -p option, if the mysql user does not have a password or simply press the Enter button to skip.

    
answered by 14.04.2018 / 15:22
source
2

First you must create the user, because if you are not assigning permissions to something non-existent, in the following way

CREATE USER 'invitado'@'localhost' IDENTIFIED BY 'contrasenia';

Now once it is created you assign permissions

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

If you want the user to only access a specific database, create the command like this

GRANT ALL PRIVILEGES ON database_name.* TO 'invitado'@'localhost';

To finish, execute the following command to update the user table and its permissions

FLUSH PRIVILEGES;

WHAT PRIVILEGES CAN I GRANT TO USERS?

  
  • ALL PRIVILEGES
  •   
  • CREATE
  •   
  • DROP
  •   
  • DELETE
  •   
  • INSERT
  •   
  • SELECT
  •   
  • uPDATE
  •   
        
    answered by 14.04.2018 в 15:20