sql >> Database teknologi >  >> RDS >> Mysql

MySQL Stored Procedure for at oprette bruger

Måske vil dette give dig nogle ideer:

DELIMITER $$

DROP PROCEDURE IF EXISTS `add_User`$$

CREATE PROCEDURE `add_User`(IN `p_Name` VARCHAR(45), IN `p_Passw` VARCHAR(200))
BEGIN
    DECLARE `_HOST` CHAR(14) DEFAULT '@\'localhost\'';
    SET `p_Name` := CONCAT('\'', REPLACE(TRIM(`p_Name`), CHAR(39), CONCAT(CHAR(92), CHAR(39))), '\''),
    `p_Passw` := CONCAT('\'', REPLACE(`p_Passw`, CHAR(39), CONCAT(CHAR(92), CHAR(39))), '\'');
    SET @`sql` := CONCAT('CREATE USER ', `p_Name`, `_HOST`, ' IDENTIFIED BY ', `p_Passw`);
    PREPARE `stmt` FROM @`sql`;
    EXECUTE `stmt`;
    SET @`sql` := CONCAT('GRANT ALL PRIVILEGES ON *.* TO ', `p_Name`, `_HOST`);
    PREPARE `stmt` FROM @`sql`;
    EXECUTE `stmt`;
    DEALLOCATE PREPARE `stmt`;
    FLUSH PRIVILEGES;
END$$

DELIMITER ;



  1. Hvordan bygger man RUNAS /NETONLY funktionalitet ind i et (C#/.NET/WinForms) program?

  2. PSQLEundtagelse:FEJL:Relationen TABLE_NAME eksisterer ikke

  3. SQL Server Trigger:Forståelse og alternativer

  4. java.lang.AbstractMethodError:com.mysql.jdbc.PreparedStatement.setBlob(ILjava/io/InputStream;)V