LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Changing Mysql user? (https://www.linuxquestions.org/questions/programming-9/changing-mysql-user-3758/)

Ricardo77uk 06-27-2001 06:15 PM

Changing Mysql user?
 
For some reason I am unble to run PHP scripts that need mysql... I get a message: Cannot connect to server!

What file or procedure do I need to change the way in which mysql runs...i can only assume it is running under root

jharris 06-28-2001 05:47 AM

Re: Changing Mysql user?
 
So its failing to connect to the server rather than failing to authenticate the user yeah?

Run a script that just contains <?PHP phpinfo() ?> and check for any clearly wrong settings in the mysql section. Also, at the risk of insulting you - you sure that the server is running! When you do a
Code:

ps -ef | grep mysql
you see the server running? And can you connect to if from the command line.

Just a few thoughts

Jamie...

Ricardo77uk 06-28-2001 09:08 AM

i think its running
 
i am able to create a database and add entires, and when I use mysqlshow it seems to work. (does this mean its ruuning?)

Only when i call for the database from a PHP script i get

'Unable to connect to database server'

any suggesttions?

Ricardo77uk 06-28-2001 09:16 AM

about the phpinfo
 
after inspecting the phpinfo i learnt that

mysql.default_host, mysql.default_password, mysql.default_port, mysql.default_socket, mysql.default_user

all of the above have 'No Value'.

Is this why my php scripts dont have a clue? If so, what do I do?


Cheers,

jharris 06-28-2001 11:25 AM

If mysql is running on the same box as Apache then you will want to set a value for mysql.default_socket. By default the mysql sock is /tmp/mysql.sock but you'll want to check that. If you got access to the server on the command line then it must be working.

If the mysql server is running on a different box then you will probably want to set values for mysql.default_host and mysql.default_port although these can be specified when you make the connection.

Remember to restart Apache when you make changes to you php.ini file.

HTH

Jamie...

Ricardo77uk 06-28-2001 01:01 PM

no joy!
 
no joy im afraid...still cannot connect!

I have no entries where it asks for default hosts, port etc etc... what should i put there, it says it will use Mysql default values if none are specified.


Im gonna do the install process again... b 4 I give up, hopefully it will work! I'll keep ya posted.

doodah 06-28-2001 01:11 PM

your problem could be caused by your php config, or it could be as simple as the code is wrong.. are you using the php functions for mysql correctly, like passing in the correct username and password, and selecting the correct db... if you post a bit of the code ill take a look...

ps.. use the code tags when you post

Ricardo77uk 06-28-2001 10:55 PM

warning messages!!!
 
Ok i re-installed apache/php and mysql.

I presume I can connect to the server from my php script as I now get several warnings...

Doodah, when you say php config do you mean the php.ini file? and how do i set Mysql to run under a particular user and password?

please dont laugh but what are code tags?
is it possible i could email you the code as they will just waste alot of resources here...

cheers

Ricardo77uk 06-29-2001 09:53 AM

I used a simple html form which calls for this php script to make entries into mysql database.

i get an error on the browser:-
Parse error: parse error in /usr/local/apache/htdocs/form.php on line 5

here is the form.php:

#<html>
#<body>
#<?php
#
#mysql_connect (localhost, mysql, pass);
#
#mysql_select_db (name);
#
#mysql_query ("INSERT INTO names (first_name, last_name)
# VALUES ('$first_name', '$last_name')
# ");

#print ($first_name);

#print (" ");

#print ($last_name);

#print ("<p>");

# print ("Thanks for submitting your name.");

# ?>
# </body>
# </html>

Ricardo77uk 06-29-2001 10:01 AM

update...
 
I added user mysql with adduser etc.. now i get this error:

Warning: Access denied for user: 'mysql@localhost' (Using password: YES) in /usr/local/apache/htdocs/form.php on line 5

mysql is running under anonoymous and doesnt allow me to add users etc.

How do i go about running mysql under a more privileged user?

Dont be shy to go into detail, I am at the brink of insanity!

jharris 06-29-2001 12:10 PM

Is sounds like the user who mysqld is running as doesn't have permissions to access the directorys/files that hold the database(s). Check your file permissions... you'll probably need to chmod and chown them.

Also when you added that use did you check that it worked on the command line using 'mysql -u username -p'

HTH

Jamie...

Ricardo77uk 06-29-2001 01:08 PM

cheers Jharris your a star!
 
Yep it was a simple as a permissions problem... It seem to connect to the database and add entries!!!

Nice one jharris -- Cheers!

I have one more question? How do i add a user for mysql? i.e. if i wanted to add the user rick and with a password 'england'

Thanks all

jharris 06-29-2001 01:25 PM

You use the grant command... IIRC something like (assuming you want to grant them the ability to do anything on any table in a database called 'myDB', and you are currently a user who can edit other users, such as root)
Code:

GRANT ALL PRIVILEGES ON myDB.* TO ric@localhost IDENTIFIED BY
'england' WITH GRANT OPTION;

This would allow user ric to connect from only localhost though! If you wanted them to be able to connection from any machine in myDomain.net then you would also use
Code:

GRANT ALL PRIVILEGES ON myDB.* TO ric@"%.myDomain.net" IDENTIFIED BY
'england' WITH GRANT OPTION;

I've found that the privileges section in the mysql manual to not be that great when you want to set permissions on specific rows etc. So good luck if you need to do this!

HTH - glad the permissions worked out :)

Jamie...

Ricardo77uk 06-30-2001 05:48 PM

the above worked and i tested a more sophisticated script and had no problems...

Thanks again!


All times are GMT -5. The time now is 09:21 PM.