当前位置: 首页 > 图文教程 > 数据库 > MYSQL > MySQL 随机密码生成代码

MYSQL
Sphinx+MySQL全文检索架构与安装
Mysql初学者:ERROR 1005错误处理
MySQL的root密码恢复的方法
注意MySQL数据库用户root密码为空
破解mysql的root密码的几种方法
修改MySQL的root密码(Linux环境)
MySQL5.0的my.cnf配置说明
Perl操作mysql数据库的方法
修改MySQL 5.0的默认100连接数
MYSQL中单一表超过4G的对策
MySQL 5.0全新的SQL句法sp_executesql
MySQL中Now()函数的详细介绍
ASP程序直接连接MYSQL数据库
mysql 1046错误解决实例
MYSQL中ERROR 1005信息处理
MYSQL的优化之关于limit优化
mysql insert详细讲解
mysql服务无法启动1067错误解决
mysql INSERT command denied to user
linux下MYSQL常见两个错误的解决办法

MYSQL 中的 MySQL 随机密码生成代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 92 ::
收藏到网摘: n/a

晚上有朋友问起,简单的写了一个。
复制代码 代码如下:

DELIMITER $$
CREATE
FUNCTION `t_girl` . `func_rand_string` ( f_num tinyint unsigned , f_type tinyint unsigned )
RETURNS varchar ( 32)
BEGIN
-- Translate the number to letter.
-- No 1 stands for string only.
-- No 2 stands for number only.
-- No 3 stands for combination of the above.
declare i int unsigned default 0;
declare v_result varchar ( 255) default '' ;
while i < f_num do
if f_type = 1 then
set v_result = concat ( v_result, char ( 97+ ceil( rand ( ) * 25) ) ) ;
elseif f_type= 2 then
set v_result = concat ( v_result, char ( 48+ ceil( rand ( ) * 9) ) ) ;
elseif f_type= 3 then
set v_result = concat ( v_result, substring ( replace ( uuid ( ) , '-' , '' ) , i+ 1, 1) ) ;
end if;
set i = i + 1;
end while;
return v_result;
END $ $
DELIMITER ;

调用方法示例:
复制代码 代码如下:

select func_rand_string(12,3);