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

MYSQL
使用mysql的mysqldump实现自动备份
MySQL数据导出和导入工具:mysqldump
怎样从Windows命令行启动您的MySQL
细化解析实现MySQL查询结果的分页显示
强大的工具 MySQL客户端命令行应用技巧
MySQL 5.0.16中出现乱码问题的解决方法
phpMyBackupPro备份恢复Mysql数据库
如何才能关闭MySQL数据库中错误提示音
数据库竟然崩溃了!马上让它恢复正常!
怎么显示 MySQL 数据库里表的概要呢?
自动恢复MySQL数据库的日志文件全教程
实例解说MySQL数据库中文问题的解决方案
优化MySQL数据库性能的几招儿好办法
MySQL加密函数保护Web网站敏感数据
使用PHP小程序清除Mysql中恼人的死连接
Mysql中用utf8存储而用gbk输出的实现
浅谈怎么才能在MySQL中直接储存图片
用特殊的MySQL运算符获得更多数据比较功能
MySQL数据库中的重要资料需要怎样保护?
假如忘记MySQL root密码应当怎样找回

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-13   浏览: 122 ::
收藏到网摘: 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);