Error generating users in SQL file

1

I receive the following error:

  

ERROR 1396 (HY000) at line 11: Operation DROP USER failed for 'garen' @ 'localhost'

When I run this code:

-- DATABASE 
-- Creamos la base de datos
DROP DATABASE IF EXISTS janitza511;
CREATE DATABASE janitza511;
USE janitza511;

-- USER 
-- DROP USER IF EXISTS "garen"@"localhost";
-- Creamos el usuario para la base de datos
-- Se dropea del todo a causa de mysql no acepta "IF EXISTS"
DROP USER garen@localhost;
FLUSH PRIVILEGES;
CREATE USER garen@localhost  IDENTIFIED BY 'CONTRASEÑA';
GRANT ALL PRIVILEGES ON *.* TO "garen"@"localhost" WITH GRANT OPTION;
FLUSH PRIVILEGES;

The command if I put it to hand, works perfectly; but if I do it from a sql, no.

I am working with MySQL and in a RaspberryPi 3.

    
asked by Fran 01.06.2017 в 10:15
source

1 answer

0

The solution is to use:

GRANT USAGE ON *.* TO 'username'@'localhost';
DROP USER 'username'@'localhost';

GRANT USAGE prevents it from giving the error "Operation DROP USER failed ..." in case the user does not exist.

    
answered by 01.06.2017 в 13:19