Dar permisos al usuario sergio en bdsainz desde la ip 1.1.1.1 y con contraseña qwerty

mysql> GRANT ALL ON bdsainz.* TO sergio@'1.1.1.1' IDENTIFIED BY 'qwerty';

mysql> REVOKE GRANT OPTION ON bdsainz.* FROM sergio@'1.1.1.1';

Ver permisos de un usuario:

SHOW GRANTS FOR "sergio"@"1.1.1.1" ;

Para ver todos los permisos hay que usar un procedimiento almacenado:

  1. USE mysql;
  2. DELIMITER //
  3. CREATE PROCEDURE showAllGrants() BEGIN
  4. DECLARE done INT DEFAULT 0;
  5. DECLARE theUser CHAR(16);
  6. DECLARE theHost CHAR(16);
  7. DECLARE cur1 CURSOR FOR SELECT user, host FROM mysql.user;
  8. DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET done = 1;
  9. OPEN cur1;
  10. REPEAT
  11. FETCH cur1 INTO theUser, theHost;
  12. IF NOT done THEN
  13. SET @sql := CONCAT('SHOW GRANTS FOR \'', theUser, '\'@\'', theHost, '\'');
  14. PREPARE grantStatement FROM @sql;
  15. EXECUTE grantStatement;
  16. DROP PREPARE grantStatement;
  17. END IF;
  18. UNTIL done END REPEAT;
  19. CLOSE cur1;
  20. END//
  21. DELIMITER ;
  22. CALL showAllGrants();

Pegado de <http://forge.mysql.com/snippets/view.php?id=95>

No permitir accesos remotos:

Editar /etc/my.cnf e incluir/descomentar la línea skip-networking dentro de [mysqld] y reiniciar mysql.

Deja una Respuesta