码迷,mamicode.com
首页 > 数据库 > 详细

第二次启用httpd24调用mysql时出现的错误

时间:2015-04-08 16:51:40      阅读:347      评论:0      收藏:0      [点我收藏+]

标签:mysql   httpd24   调用出错   

# 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

技术分享其它的就不显示了。

查看日志

# 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


好吧,数据库每打开

# service mysqld start        #设置过开机启动,不知道为什么没有用

再到浏览器刷新还是没有用

进入mysql

# 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主机,第一次就创建了,可能不小心给删了,好吧,再重新创建

mysql> create user ‘root‘@‘www.crwolf.com‘ identified by ‘welcome‘;
ERROR 1396 (HY000): Operation CREATE USER failed for ‘root‘@‘www.crwolf.com‘

你妹,这又是怎么回事,网上找了好久,说是bug了,解决方法:把要创建的用户删除一次,再创建,别忘记flush

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      |             |                                           |
+----------------+-------------+-------------------------------------------+

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

# 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还没有权限?

mysql> use mysql 
Database changed
mysql> grant select on table1.test to root  ;
Query OK, 0 rows affected (0.00 sec)

再去刷新页面,终于好了。

技术分享

本文出自 “三哥” 博客,请务必保留此出处http://523958392.blog.51cto.com/9871195/1629939

第二次启用httpd24调用mysql时出现的错误

标签:mysql   httpd24   调用出错   

原文地址:http://523958392.blog.51cto.com/9871195/1629939

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!