设为首页 收藏本站
查看: 528|回复: 0

[经验分享] 第二次启用httpd24调用mysql时出现的错误

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-4-9 09:03:03 | 显示全部楼层 |阅读模式
# vim /etc/httpd24/httpd.conf
PidFile "/var/run/httpd/httpd.pid"
LoadModule php5_module        modules/libphp5.so
DocumentRoot "/web/htdocs"
<Directory "/web/htdocs">
# vim /web/htdocs/index.php        #里面的内容是摘抄的
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<p>测试</p>
<table border="1"  width="80%" cellpadding="0">
<tr>
             <td width="10%" align="center">Id</td>
             <td width="20%" align="center">Name</td>
             <td width="10%" align="center">Age</td>
             <td width="10%" align="center">Sex</td>
             <td width="30%" align="center">Address</td>
             <td width="20%" align="center">DoWith</td>
</tr>
<?php
             //连接数据库
            //打开一个连接,连接到本地mysql数据库
            $conn=mysql_connect("www.crwolf.com","root","welcome");//ip,user,pwd
            //选择操作的资料库        
            mysql_select_db("table1",$conn);// 资料库名称,连接
           $sql="select * from test";
           //用mysql_query函数从资料库中查询
            mysql_query("set names UTF-8");//处理中文乱码问题,gbk可以是其它值
            $result=mysql_query($sql,$conn);// search  sql, connection
            //循环读取记录
            while($row=mysql_fetch_array($result)){
?>
            <tr>
                    <td width="10%" align="center"><?php echo $row["ID"] ?></td>
                    <td width="20%" align="center"><?php echo $row["NAME"] ?></td>
                    <td width="10%" align="center"><?php echo $row["Age"] ?></td>
                    <td width="10%" align="center"><?=$row["SEX"]?></td>
                    <td width="30%" align="center"><?=$row["Address"]?></td>
                    <td width="20%" align="center"><a href="#" mce_href="#"
                      onClick="<?php    doDel($row["ID"]) ?>">删除</a></td>
                </tr>

# service httpd24 restart

问题来了,到浏览器输入192.168.1.9
QQ截图20150409090237.png 其它的就不显示了。
查看日志
1
# less error_log



[Wed Apr 08 08:58:56.795374 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_connect(): Can't connect to MySQL server on 'www.crwolf.com' (111) in /web/htdocs/index.php on line 15
[Wed Apr 08 08:58:56.795409 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_select_db() expects parameter 2 to be resource, boolean given in /web/htdocs/index.php on line 17
[Wed Apr 08 08:58:56.795448 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_query(): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /web/htdocs/index.php on line 21
[Wed Apr 08 08:58:56.795457 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_query(): A link to the server could not be established in /web/htdocs/index.php on line 21
[Wed Apr 08 08:58:56.795475 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_query() expects parameter 2 to be resource, boolean given in /web/htdocs/index.php on line 22
[Wed Apr 08 08:58:56.795483 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, null given in /web/htdocs/index.php on line 24
[Wed Apr 08 08:58:56.795490 2015] [:error] [pid 4309] [client 192.168.1.9:58773] PHP Warning:  mysql_close() expects parameter 1 to be resource, boolean given in /web/htdocs/index.php on line 38

好吧,数据库每打开
1
# service mysqld start        #设置过开机启动,不知道为什么没有用



再到浏览器刷新还是没有用
进入mysql
1
2
3
4
5
6
7
8
9
10
11
12
# mysql
mysql> use mysql
Database changed
mysql> SELECT host,user,password FROM user;
+-------------+-------------+-------------------------------------------+
| host        | user        | password                                  |
+-------------+-------------+-------------------------------------------+
| localhost   | root        | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 |
| 127.0.0.1   | root        |                                           |
| ::1         | root        |                                           |
| localhost   |             |                                           |
+-------------+-------------+-------------------------------------------+



怎么会没有root用户,www.crwolf.com主机,第一次就创建了,可能不小心给删了,好吧,再重新创建
1
2
mysql> create user 'root'@'www.crwolf.com' identified by 'welcome';
ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'www.crwolf.com'



你妹,这又是怎么回事,网上找了好久,说是bug了,解决方法:把要创建的用户删除一次,再创建,别忘记flush
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mysql> drop user 'root'@'www.crwolf.com';    #都没有这个,还要再删除,挺郁闷的
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> create user 'root'@'www.crwolf.com' identified by 'welcome';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT host,user,password FROM user;
+----------------+-------------+-------------------------------------------+
| host           | user        | password                                  |
+----------------+-------------+-------------------------------------------+
| localhost      | root        | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 |
| 127.0.0.1      | root        |                                           |
| www.crwolf.com | root        | *DF216F57F1F2066124E1AA5491D995C3CB57E4C2 |
| ::1            | root        |                                           |
| localhost      |             |                                           |
+----------------+-------------+-------------------------------------------+



这次有用户了吧,再刷新页面,怎么还是刚刚的页面,再看日志
1
# less error_log



[Wed Apr 08 10:14:37.502684 2015] [:error] [pid 5510] [client 192.168.1.9:60334] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /web/htdocs/index.php on line 24
[Wed Apr 08 10:18:46.821670 2015] [:error] [pid 5512] [client 192.168.1.9:60351] PHP Warning:  mysql_fetch_array() expects parameter 1 to be resource, boolean given in /web/htdocs/index.php on line 24

登陆数据库的用户没有数据库的权限(这个只是我的,可能还有别的原因),到mysql授权。不解处:root还没有权限?
1
2
3
4
mysql> use mysql
Database changed
mysql> grant select on table1.test to root  ;
Query OK, 0 rows affected (0.00 sec)



再去刷新页面,终于好了。
QQ截图20150409090247.png


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-55256-1-1.html 上篇帖子: rhel、centos、fedora使用yum安装mysql community server 下篇帖子: MySQL级联+双主方案 mysql
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表