Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed apache2, php5, mysql-server, php5-mysql, phpmyadmin in that order on Ubuntu 12.04 with the Software Center. Apache and PHP works fine, no problems. Also, if I try to work with MySQL via phpmyadmin, everything works as expected. Problems start, when I want to use MySQL via PHP. For this I tried the following script:

$connection = mysql_connect($host, $user, $pw) OR die(mysql_errno()." ".mysql_error());
mysql_select_db($db, $connection) OR die(mysql_errno()." ".mysql_error());

This returns "1046 No database selected". I'm sure that the database exists, I even tried it with the standard "test"-database and root as the user. What made me really curious, is that when I use a non-existent user ("asdf"), the same message appears and no failure from the mysql_connect-function.

This leads me to the suspicion, that I struggle with user rights in the Linux system, because it works with phpmyadmin, which is not installed via a webinstaller but via the Software Center. I can only guess that hence, phpmyadmin has other rights to access MySQl than PHP, but I don't know, how to approach the problem. After trying and googleing for hours, I feel a bit lost now. Please help me.

share|improve this question

This does not seem to be Ubuntu related per se.
For figuring out the permissions required for PHP files you can go through

phpMyAdmin will most probably be located in /usr/share/phpmyadmin you can look up the settings it is using. might be useful which suggests looking at

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.