LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-27-2001, 06:15 PM   #1
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Rep: Reputation: 15
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
 
Old 06-28-2001, 05:47 AM   #2
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
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...
 
Old 06-28-2001, 09:08 AM   #3
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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?
 
Old 06-28-2001, 09:16 AM   #4
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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,
 
Old 06-28-2001, 11:25 AM   #5
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
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...
 
Old 06-28-2001, 01:01 PM   #6
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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.
 
Old 06-28-2001, 01:11 PM   #7
doodah
Member
 
Registered: Apr 2001
Location: Columbus,OH
Distribution: slackware
Posts: 122

Rep: Reputation: 15
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
 
Old 06-28-2001, 10:55 PM   #8
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
Unhappy 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
 
Old 06-29-2001, 09:53 AM   #9
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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>
 
Old 06-29-2001, 10:01 AM   #10
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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!
 
Old 06-29-2001, 12:10 PM   #11
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
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...
 
Old 06-29-2001, 01:08 PM   #12
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
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
 
Old 06-29-2001, 01:25 PM   #13
jharris
Senior Member
 
Registered: May 2001
Location: Bristol, UK
Distribution: Slackware, Fedora, RHES
Posts: 2,243

Rep: Reputation: 47
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...
 
Old 06-30-2001, 05:48 PM   #14
Ricardo77uk
Member
 
Registered: Jun 2001
Location: London England
Distribution: Suse 7.1
Posts: 45

Original Poster
Rep: Reputation: 15
Talking

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

Thanks again!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Changing a User carlosinfl Linux - General 11 11-29-2005 02:25 PM
User id (needs changing) podollb Linux - Software 2 05-15-2004 09:26 AM
Changing date format in MySQL table vous Linux - Software 8 09-03-2003 06:30 AM
libnss-mysql (Store your UNIX user accounts in MySQL) markus1982 Linux - Security 0 01-26-2003 02:24 AM
screwed up mysql by changing password, help! JustinHoMi Linux - General 0 01-28-2002 04:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:17 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