LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   MySQL db exists, can't connect to it, do I need to add user to it? (https://www.linuxquestions.org/questions/linux-general-1/mysql-db-exists-cant-connect-to-it-do-i-need-to-add-user-to-it-132645/)

Hero Doug 01-08-2004 02:55 AM

MySQL db exists, can't connect to it, do I need to add user to it?
 
I'm using Fedora, but I don't think it'll matter.

Anyways I made a database from the command line, but when I try to access it access is always denied. Do I need to add a user to it, set permissions etc?

If so, how to I do it?

Thanks.

cheesy1979 01-08-2004 06:32 AM

You need to tell us more info!! Hope this doesn't sound patronising.

Assuming you're using the command line:
Is the server running? ie, mysqld_safe

Are you logged in (ie you get the "mysql>" prompt)?
If so, what command are you using? ie, mysql -uroot -prootpassword

Tell us the exact commands you are using and the exact error messages.

Cheesy

Hero Doug 01-08-2004 01:26 PM

I was in the terminal when I made the db, i used the following command to make the db.

mysqladmin create search

I know it exists because I thought it might have not made it the first time and I tried it again, it gave me a message saying the db already exists.

This is the command I used to connect to it.

$con = mysql_connect("localhost")or die("Couldn't connect to MySQL server. Please send the following information to the site admin. <br /><br />: ".mysql_error());
$db = "search";
mysql_select_db($db, $con)or die("Connect Error: ".mysql_error());

I;ve also tried puting the root username and password in the connection variable, no luck.

This is the error

Connect Error: Access denied for user: '@localhost' to database 'search'

cheesy1979 01-08-2004 05:56 PM

You seem to be connecting to the server ok but don't have any privileges for your database which I can't understand because the root user should work on any database.

Also, the error message is intriguing. The user name is missing. Have you typed the complete error message below? It should tell you something like:

Connect Error: Access denied for user: 'root@localhost' to database 'search'



I suggest trying this- it can't hurt! It creates a new user called admin, with the password adminpass, who has privileges to do anything to your search database.

from the command line log-in to the server as the root:
mysql -uroot -proot'spassword

enter the following command:
grant all privileges on search.* admin@localhost identified by 'adminpass' with grant option;

logout:
\q;

change the mysql_connect("localhost") in your php script to:
mysql_connect("localhost","admin","adminpass")


If that doesn't work then I'm stuck. Like I said before, I don't understand why it doesn't work as root.

Hero Doug 01-08-2004 07:19 PM

Maybe I need to make a database with all the users in it first!

I've tried adding my normal account to the mysql group, and I've tried to connect to the server as both root and the normal account, from both php scripts and the command line. Both were denied.

I can make a connection to the server as anyone, but as soon as I try to access a database all access is denied.

After I got to the mysql command prompt and tried toenter the code you posted, which produced an error.

ERROR 1064: You have an error in your SQL syntax near 'herodoug@localhost identified by pass with grant option' at line 1

Is there any way to display all the databases there currently are? (Hopefully I'll have founf the answer by the time you respond)

I was right, I did find the answer before anyone responded. There are three databases.

mysql
search
test

Robert0380 01-08-2004 11:59 PM

grant all privileges on search.* admin@localhost identified by 'adminpass' with grant option;


i think you need to add the word "to"

grant all privileges on serach.* to admin@localhost


try it with "to".


here is the link:

http://www.mysql.com/doc/en/GRANT.html


cheesy1979 01-09-2004 04:18 AM

Oops!
 
Doh! As Bob said I forgot the 'to'. Try

grant all privileges on search.* to admin@localhost identified by 'adminpass' with grant option;


If that don't work then I'm stumped!

Hero Doug 01-09-2004 03:54 PM

I actually found the answer on another forum. It has to do with setting up the MySQL super user first.

http://forums.devshed.com/showthread...88626#post4886


All times are GMT -5. The time now is 08:10 AM.