You are here: mysql_connect() default connection (problem fixed) « PHP SQL « IT news, forums, messages
mysql_connect() default connection (problem fixed)

Posted by Cong on 02/01/07 21:56

I just solve this problem so I just post up the solution in case
anyone else has this problem.
I got php 5.1 and mysql version 5.0 install on Fedora 5.0. anyway the
problem when I try to connect to mysql using this string below

$link = mysql_connect('localhost','user','password')

I'm keep getting this error

PHP Warning: mysql_query(): supplied argument is not a valid MySQL-
Link resource in /var/www/html/login.php

this drive me nut becuase I did create proper priviliage inside the
table mysql. so I decide to run this below

<?php
$link = mysql_connect() or die(mysql_error());
$result = mysql_query("SELECT SESSION_USER(), CURRENT_USER();");
$row = mysql_fetch_row($result);
echo "SESSION USER: ", $row[0], "<br>\n";
echo "CURRENT USER: ", $row[1], "<br>\n";
?>

it echo back 'apache@localhost'

it actually connect using username apache WITHOUT password by
default!!! If you create an apache with password it won't work (in
mysql database) or any other user and password combo.
so I comb the web for two days straight and finally I found out that:
If you run mysql in SAFEMODE it won't accept any password at all.
so run

ps aux | grep mysqld

root 26825 0.1 0.6 4448 1260 pts/1 S 13:53 0:00 /bin/
sh /usr/bin/MYSQLD_SAFE --defaults-file=/etc/my.cnf --pid-file=/var/
run/mysqld/mysqld.pid --log-error=/var/log/mysqld.log
mysql 26861 0.5 9.6 136648 18360 pts/1 Sl 13:53 0:00 /usr/
libexec/mysqld --defaults-file=/etc/my.cnf --basedir=/usr --datadir=/
var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/mysqld.pid --
skip-external-locking --socket=/var/lib/mysql/mysql.sock
root 26882 0.0 0.3 3916 672 pts/1 R+ 13:53 0:00 grep
mysqld

kill -9 26825

this should take care of the problem. I wonder why Fedora allow to
run mysqld_safe and mysqld at the same.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация