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

MYSQL
MYSQL教程:保护MySQL安装程序文件
MYSQL教程:MySQL服务器权限表
MYSQL教程:建立加密连接
MYSQL教程:检查数据表和修复数据表
MYSQL教程:备份数据库
MYSQL教程:使用备份恢复数据
MYSQL教程:MySQL程序介绍
MYSQL教程:数据库具体操作
MySQL Explain命令用于查看执行效果
Phpnow服务器软件集成套件的安装问题和解决方法
SQLyog工具可以分析Mysql数据库
AppServ安装配置Apache+PHP+Mysql环境
MySQL异常:未验证的用户尝试登录
Mysql教程:MYSQL创建触发程序
MYSQL代码:定期备份Mysql数据库
PHP实现的Mysql读写分离
PHP教程:MySQL读写分离由PHP实现
用PHPnow搭建PHP+MYSQL网站开发环境
瑞典300M可绑米免费PHP空间
常见的十款PHP+MySql类免费CMS系统

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


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