Home  >  Article  >  Database  >  MySQL生成随机密码_MySQL

MySQL生成随机密码_MySQL

WBOY
WBOYOriginal
2016-06-01 13:35:441013browse

bitsCN.com

MySQL生成随机密码

 

我简化了步骤, 比之前的更加简洁,常规生成随机密码。

[sql] 

DELIMITER $$  

  

  

USE `t_girl`$$  

  

  

DROP FUNCTION IF EXISTS `func_range_string_mod`$$  

  

  

CREATE DEFINER=`root`@`localhost` FUNCTION `func_range_string_mod`(  

    f_num INT UNSIGNED -- Total strings.  

    ) RETURNS VARCHAR(200) CHARSET latin1  

BEGIN  

      

      DECLARE i INT UNSIGNED DEFAULT 0;   

      DECLARE v_result VARCHAR(200) DEFAULT '';   

      DECLARE v_dict VARCHAR(200) DEFAULT '';  

      SET v_dict = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';  

      SET v_dict = LPAD(v_dict,200,v_dict);  

      WHILE i

      DO   

    SET v_result = CONCAT(v_result,SUBSTR(v_dict,CEIL(RAND()*200),1));  

        SET i = i + 1;   

      END WHILE;    

      RETURN v_result;   

    END$$  

  

  

DELIMITER ;  

 

调用方法:

 

select func_range_string_mod(20); 代表需要生成20个字符长度的密码。
 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn