sql >> データベース >  >> RDS >> Mysql

変数でGRANTを使用する方法は?

    SET @object = '*.*';
    SET @user = '''user1''@''localhost''';
    
    SET @query = CONCAT('GRANT UPDATE ON ', @object, ' TO ', @user);
    PREPARE stmt FROM @query;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
    
    DROP PROCEDURE IF EXISTS `test`.`spTest`$$
    
    CREATE DEFINER=`root`@`localhost` PROCEDURE `spTest`( varLogin char(16), varPassword char(64) )
    BEGIN
        DECLARE varPasswordHashed CHAR(41);
        SELECT PASSWORD(varPassword) INTO varPasswordHashed;
    
        # Any of the following 3 lines will cause the creation to fail
        CREATE USER [email protected]'localhost' IDENTIFIED BY varPassword;
        GRANT USAGE ON test.* TO [email protected]'localhost' IDENTIFIED BY varPassword;
        GRANT USAGE ON test.* TO [email protected]'localhost' IDENTIFIED BY PASSWORD varPasswordHashed;
    
        ## The following 3 lines won't cause any problem at create time
        CREATE USER [email protected]'localhost' IDENTIFIED BY 'AnyPassordString';
        GRANT USAGE ON test.* TO [email protected]'localhost' IDENTIFIED BY 'AnyPassordString';
        GRANT USAGE ON test.* TO [email protected]'localhost' IDENTIFIED BY PASSWORD  'AnyPassordString';  
    END$$
    
    DELIMITER;
    



    1. データベースが選択されていません-PHPとMySQL

    2. Oracleで列タイトルの二重引用符をエスケープできますか?

    3. OracleのBIN_TO_NUM()関数

    4. MySQLの2つの日時の間のマイナス演算子の動作は何ですか?