apache一个奇怪的错误

lrenwang , 2012/01/21 09:02 , Php , 评论(0) , 阅读(48) , Via 本站原创
500错误
Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@dummy-host.localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.



apache错误日志是这么写的
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.


找了好长时间,我的目录结构是这样的 80端口访问的是 ...www/ 81端口访问的是....www/81
因为80端口有个.htaccess 所以出现这种奇怪问题, 改成80访问 ../www/80 这样就OK了
不过有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值,这事真让我遇上了,在对mysql5.1.32建立远程用户时。

分别对'%'和'localhost'授权解决。


相关参考资料:

MySQL 赋予用户权限命令的简单格式可概括为:

grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。
grant select on testdb.* to common_user@'%'
grant insert on testdb.* to common_user@'%'
grant update on testdb.* to common_user@'%'
grant delete on testdb.* to common_user@'%'
或者,用一条 MySQL 命令来替代:

grant select, insert, update, delete on testdb.* to common_user@'%'
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。
grant 创建、修改、删除 MySQL 数据表结构权限。

grant create on testdb.* to developer@'192.168.0.%';
grant alter  on testdb.* to developer@'192.168.0.%';
grant drop   on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 外键权限。

grant references on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 临时表权限。

grant create temporary tables on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 索引权限。

grant index on  testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 视图、查看视图源代码 权限。

grant create view on testdb.* to developer@'192.168.0.%';
grant show   view on testdb.* to developer@'192.168.0.%';

grant 操作 MySQL 存储过程、函数 权限。

grant create routine on testdb.* to developer@'192.168.0.%';  -- now, can show procedure status
grant alter  routine on testdb.* to developer@'192.168.0.%';  -- now, you can drop a procedure
grant execute        on testdb.* to developer@'192.168.0.%';
三、grant 普通 DBA 管理某个 MySQL 数据库的权限。
grant all privileges on testdb to dba@'localhost'
其中,关键字 “privileges” 可以省略。

四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。
grant all on *.* to dba@'localhost'
五、MySQL grant 权限,分别可以作用在多个层次上。
1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。
grant all    on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库
2. grant 作用在单个数据库上:

grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。

3. grant 作用在单个数据表上:

grant select, insert, update, delete on testdb.orders to dba@localhost;

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to dba@localhost;

5. grant 作用在存储过程、函数上:

grant execute on procedure testdb.pr_add to 'dba'@'localhost'
grant execute on function  testdb.fn_add to 'dba'@'localhost'
六、查看 MySQL 用户权限
查看当前用户(自己)权限:

show grants;
查看其他 MySQL 用户权限:

show grants for dba@localhost;
七、撤销已经赋予给 MySQL 用户权限的权限。
revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

grant  all on *.* to   dba@localhost;
revoke all on *.* from dba@localhost;
八、MySQL grant、revoke 用户权限注意事项
1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。

2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“

grant select on testdb.* to dba@localhost with grant option;
这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。






----------------------------------------------------------------------------------------------

授权命令GRANT 语句的语法如下:
GRANT privileges (columns)
ON what
TO user IDENTIFIEDBY "password"
WITH GRANT OPTION
对用户授权
mysql>grant rights on database.* to user@host identified by "pass";
例1:
增加一个用户test1密码为abc,让他可以在任何主机上登录,并对所有数据库有查询、插入、修改、删除的权限。
grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";
ON 子句中*.* 说明符的意思是“所有数据库,所有的表”
例2:
增加一个用户test2密码为abc, 让他只可以在localhost上登录,并可以对数据库mydb进行查询、插入、修改、删除的操作。
grant select,insert,update,delete on mydb.* to test2@localhost identified by "abc";
例子3
增加一个用户custom,他能从主机localhost、server.domain和whitehouse.gov连接。他只想要从 localhost存取bankaccount数据库,从whitehouse.gov存取expenses数据库和从所有3台主机存取customer 数据库。他想要从所有3台主机上使用口令stupid。

为了使用GRANT语句设置个用户的权限,运行这些命令:
shell> mysql --user=root mysql
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON bankaccount.* TO custom@localhost IDENTIFIED BY 'stupid';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON expenses.* TO custom@whitehouse.gov IDENTIFIED BY 'stupid';
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON customer.* TO custom@'%' IDENTIFIED BY 'stupid';
==============================================
权限信息用user、db、host、tables_priv和columns_priv表被存储在mysql数据库中(即在名为mysql的数据库中)。
权限 列 Context
select Select_priv 表
insert Insert_priv 表
update Update_priv 表
delete Delete_priv 表
index Index_priv 表
alter Alter_priv 表
create Create_priv 数据库、表或索引
drop Drop_priv 数据库或表
grant Grant_priv 数据库或表
references References_priv 数据库或表
reload Reload_priv 服务器管理
shutdown Shutdown_priv 服务器管理
process Process_priv 服务器管理
file File_priv 在服务器上的文件存取


1.select、insert、update和delete权限 允许你在一个数据库现有的表上实施操作,是基本权限
2.alter权限允许你使用ALTER TABLE
3.create和drop权限允许你创建新的数据库和表,或抛弃(删除)现存的数据库和表 如果你将mysql数据库的drop权限授予一个用户,该用户能抛弃存储了MySQL存取权限的数据库!
4.grant权限允许你把你自己拥有的那些权限授给其他的用户。
你不能明显地指定一个给定用户应该被拒绝存取。即,你不能明显地匹配一个用户并且然后拒绝连接。你不能指定一个用户有权创建立或抛弃一个数据库中的表,也不能创建或抛弃数据库本身。 可以同时列出许多被授予的单个权限。
例如,如果想让用户能读取和修改已有表的内容,但又不允许创建新表或删除表,可按如下授权:
GRANT SELECT,INSERT,DELETE,UPDATE ON samp_db.* TO 'user'@'%' IDENTIFIEDBY "pass"





为什么使用了Grant all on db.* to user identified by "pass"后,在主机上访问数据库还会出现ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES) 的错误提示?

解答方法如下:运行命令 Grant all on db.* to 'user'@'localhost' identified by "pass"

原因是:当不加@选项时,效果与加@'%'是一样的,'%'从名义上包括任何主机,(%必须加上引号,不然与@放在一起可能不会被辨认出。)不过有些时候(有些版本)'%'不包括localhost,要单独对@'localhost'进行赋值

MySQL 优化Order By Rand()执行效率

lrenwang , 2012/01/15 15:06 , MySQL , 评论(0) , 阅读(74) , Via 本站原创
最近由于需要大概研究了一下MYSQL的随机抽取实现方法。举个例子,要从tablename表中随机提取一条记录,大家一般的写法就是:SELECT * FROM tablename ORDER BY RAND() LIMIT 1。

但是,后来我查了一下MYSQL的官方手册,里面针对RAND()的提示大概意思就是,在ORDER BY从句里面不能使用RAND()函数,因为这样会导致数据列被多次扫描。但是在MYSQL 3.23版本中,仍然可以通过ORDER BY RAND()来实现随机。

但是真正测试一下才发现这样效率非常低。一个15万余条的库,查询5条数据,居然要8秒以上。查看官方手册,也说rand()放在ORDER BY 子句中会被执行多次,自然效率及很低。
You cannot use a column with RAND() values in an ORDER BY clause, because ORDER BY would evaluate the column multiple times.
搜索Google,网上基本上都是查询max(id) * rand()来随机获取数据。
SELECT *
FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * (SELECT MAX(id) FROM `table`)) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id ASC LIMIT 5;
但是这样会产生连续的5条记录。解决办法只能是每次查询一条,查询5次。即便如此也值得,因为15万条的表,查询只需要0.01秒不到。

下面的语句采用的是JOIN,mysql的论坛上有人使用
SELECT *
FROM `table`
WHERE id >= (SELECT FLOOR( MAX(id) * RAND()) FROM `table` )
ORDER BY id LIMIT 1;
我测试了一下,需要0.5秒,速度也不错,但是跟上面的语句还是有很大差距。总觉有什么地方不正常。

于是我把语句改写了一下。
SELECT * FROM `table`
WHERE id >= (SELECT floor(RAND() * (SELECT MAX(id) FROM `table`)))  
ORDER BY id LIMIT 1;
这下,效率又提高了,查询时间只有0.01秒

最后,再把语句完善一下,加上MIN(id)的判断。我在最开始测试的时候,就是因为没有加上MIN(id)的判断,结果有一半的时间总是查询到表中的前 面几行。
完整查询语句是:
SELECT * FROM `table`
WHERE id >= (SELECT floor( RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`)) + (SELECT MIN(id) FROM `table`)))  
ORDER BY id LIMIT 1;

SELECT *
FROM `table` AS t1 JOIN (SELECT ROUND(RAND() * ((SELECT MAX(id) FROM `table`)-(SELECT MIN(id) FROM `table`))+(SELECT MIN(id) FROM `table`)) AS id) AS t2
WHERE t1.id >= t2.id
ORDER BY t1.id LIMIT 1;
最后在php中对这两个语句进行分别查询10次,
前者花费时间 0.147433 秒
后者花费时间 0.015130 秒
看来采用JOIN的语法比直接在WHERE中使用函数效率还要高很多。
IE选项-程序-默认的Web浏览器中去除提示的勾选。 在win7里面这么搞是不好使的 哈哈
另外window7对IE选项-程序 里面所有设置都不好使


经过本人的研究方法如下:
1、开始>>运行>>输入"Regedit"打开注册表;
2、依次定位至"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main";
3、在Main上右键,选择权限;看看组和用户名里面有没有当前用户, 没有就添加上(点添加后,在输入的对象里面填写当前用户, 如果不知道帐号, 我的电脑->控制面板->帐户管理),然后在点击完全控制
4、IE选项-程序-默认的Web浏览器中去除提示的勾选。
成功解决!!


说白了就是当前用户没有操作注册表的权限,自然改不了 ....


关闭ie8设置成默认浏览器的提示也是这么搞

PHP Warning:  PHP Startup: pcinfo: Unable to initialize module
Module compiled with module API=20060613, debug=1, thread-safety=1
PHP    compiled with module API=20060613, debug=0, thread-safety=1
These options need to match

这是说 "Module compiled"  "PHP    compiled" 这两个应该匹配

分页: 2/36 第一页 上页 1 2 3 4 5 6 7 8 9 10 下页 最后页 [ 显示模式: 摘要 | 列表 ]