LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-14-2004, 07:06 AM   #1
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Rep: Reputation: 15
cannot connect to mysql database


hi.
i have installed fedora core 2. i have working php and apache on, but mysql give me some problems:
i can connect to the mysql server with the command "mysql_connect();" but when i try to connect to a database "mysql_select_db("database");" i get a FALSE result.
the scritp that i have tried to use is this:

/*terminal*/
mysql> CREATE DATABASE pippo;
Query OK, 1 row affected (0.00 sec)
/***********/

<?
if(!mysql_connect("localhost", "", ""))
die("CONNECTION TO MYSQL FAILED<br>");
else
echo"CONNECTED SUCCESSFUL TO MYSQL<br>";


if(!mysql_select_db("pippo"))
die("DATABASE SELECTION FAILED<br>");
else
echo"SUCCESSFUL SELECTED DATABASE<br>";
?>

the code is ok, i have tried it on windows and it works.

thank you.

Matteo
 
Old 07-14-2004, 09:18 AM   #2
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
Maybe you need something in the database?

Can you do something like this and tell me what error message you get:

mysql_select_db("pippo") or die(mysql_error());
 
Old 07-14-2004, 10:15 AM   #3
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
hi
the error i get using that line of code is:

Access denied for user: '@localhost' to database 'pippo'

maybe i have to set some config files?

thank you so much

Matteo
 
Old 07-14-2004, 02:00 PM   #4
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
Are you sure that worked on Windows? It looks like you forgot to pass the id of the mysql_connect command to the mysql_select_db in the arguments for it, like so:

$db_id = mysql_connect("localhost","","");
mysql_select_db("pippo",$db_id);

I'm not sure if it works otherwise.
If that doesn't work, try setting a username and password for mysql.

Good luck
 
Old 07-14-2004, 02:10 PM   #5
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
hm...
i have solved the problem setting a username for the database with the command "mysql_permissions" (or something similar) form the shell and connecting to mysql using that username and connecting to that database... but i don't understand WHY on windows i can create select delete databases without setting anything.... really windows is easier than linux...maybe for my work i will use windowd to develop my pages!

thx Matteo
 
Old 07-14-2004, 02:43 PM   #6
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
I don't think thats a particularly useful feature... More unsafe than anything
 
Old 07-15-2004, 04:10 AM   #7
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
i have copmpletely solved my problem:
to create databases freely i have to log to the mysql server as "root" user (mysql_connect("localhost", "root", "")) and then i am free to do what i want...
 
Old 07-15-2004, 05:43 AM   #8
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
I'm still curious as to how that worked, as you didn't pass the id of the mysql_connect command. Does it automagically use the last database you connected to?
 
Old 07-15-2004, 06:30 AM   #9
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
yes. if you don't specify any db_id, it uses the last db you referred to. you can also check it on

http://php.it/manual/it/function.mysql-select-db.php (italian)
http://www.zend.com/manual/function.mysql-select-db.php (english)

but i still dont understand WHY on linux i have to connect to mysql as "root" (mysql_connect("localhost", "root", "")) and in windows is not necessary to specify to connect with root user...
 
Old 07-15-2004, 06:37 AM   #10
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
Thanks for the link.
Maybe not specifying a username on windows is equivalent to specifying root on linux? It was probably advised against allowing a no-user no-pass system for MySQL on Linux.
 
Old 07-15-2004, 06:47 AM   #11
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
yes maybe... surely linux is safer than windows...in fact if i should put the php site i have developed (very simple..but hey man, i have started studying php one week ago..!) on my machine as a server with windows everybody could create databases or delete them...and that's not good!
 
Old 07-15-2004, 06:56 AM   #12
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
*nods*
PHP is easy if you have background programming knowledge from any of the C family of languages. It's definitely the number one time saver.
 
Old 07-15-2004, 07:05 AM   #13
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
what do you think about ASP?
 
Old 07-15-2004, 08:02 AM   #14
BluePyre
Member
 
Registered: Mar 2004
Location: London
Distribution: Mandrake 10
Posts: 172

Rep: Reputation: 30
Well, put simply, a common way to interface with ASP is VBScript, and there's no way i'm going to design a site that only works with Internet Explorer.
I admit I haven't used ASP much, but from what i've read and been told, it allows for the same usage as PHP.
I prefer linux servers for my websites as well as they normally have Cron, g++, and other useful programs, which means no chance for it.

Plus I like my semi colons and my dollar symbols

Last edited by BluePyre; 07-15-2004 at 08:03 AM.
 
Old 07-15-2004, 08:23 AM   #15
mrosati
Member
 
Registered: Nov 2003
Location: Mestre - ITALY
Distribution: Debian sarge
Posts: 132

Original Poster
Rep: Reputation: 15
i think the same as you...but usually using linux servers and php is synonimous of "hard"...people think "why i have to spend hours to do a thing on linux when i can do it spending 5 minutes on windows? it's the price to pay for more security...
one more thing:
(for example)
i work for a company who produces php sites. someone tells me to develop a site that interacts with mysql. when i write the site i have to suppose that the databases i will use are already created (by the server administrators) or it is my duty to create databases with my scripts? in other words, it is the programmer's duty to create databases or he has only to interact with these?

maybe you have more experience in this and you can explain how does it work!

thank you

Matteo
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. suziecorbett Linux - Software 8 10-09-2008 01:52 AM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
Unable to connect to (working) mySQL database rcs1000 Linux - Software 1 10-16-2005 07:23 AM
cannot connect to mysql database from php rocordial Linux - Software 2 08-21-2005 02:05 PM
cannot connect to mysql database externally lsimon4180 Linux - Software 17 03-02-2005 12:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration