用MySQL 生成随机密码
晚上有朋友问起,简单的写了一个。
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);
相关文档:
启动mysql: /etc/rc.d/init.d/mysql start
修改密码: 格式:mysqladmin -u用户名 -p旧密码 password 新密码
使用密码登录: mysql -u root -p
显示数据库: show databases;
选择数据库: use 数据库名;
显示表: show tables;
显示表结构: descibe 表名;
远程登录mysql需要开启� ......
一、设置数据库编码
安装mysql时可选择编码,如果已经安装过,可以更改文件my.ini(此文件在mysql的安装目录下)中的配制以达到目的;打开文件找到两处:
[client]
port=3306
[mysql]
default-character-set=gb2312
# The default character set that will be used when a new
schema or table is
# created and
n ......
使用mysql 经常会遇到编码问题,而导致程序出现乱码,mysql 在以下几个地方会涉及到编码格式
数据库编码
服务器编码
连接编码
客户端编码
下面是一个典型的示例, 运行 mysql -u root
查看编码 mysql>status
mysql Ver 14.7 Distrib 4.1.14, for Win32 (ia32)
Connection id: 90
Current database: yitian ......
9.3 MySQL存储过程
MySQL 5.0以后的版本开始支持存储过程,存储过程具有一致性、高效性、安全性和体系结构等特点,本节将通过具体的实例讲解PHP是如何操纵MySQL存储过程的。
实例261:存储过程的创建
这是一个创建存储过程的实例
录像位置:光盘\mingrisoft\09\261
实例说明
为了保证数据的完整性、一致性,提 ......