Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Bagaimana cara menggunakan GRANT dengan variabel?

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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Apakah praktis untuk menormalkan tabel secara dinamis?

  2. Desain database untuk pembuat formulir kustom (dan penyimpanan hasil)

  3. Akses DB5 ke MySQL secara otomatis

  4. Menghapus Substring yang Digandakan

  5. Tidak dapat terhubung ke server MySQL jarak jauh dengan kesalahan 61