Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Connecting to MySQL Server via PHP

Status
Not open for further replies.

JRB-Bldr

Programmer
May 17, 2001
3,281
US
I have doubly posted this question since I wasn't sure if it was most applicable to the PHP forum area or the MySQL area. So I apologize for the duplication...

I have many years of development behind me with other languages and with MS SQL Server, BUT I am a total 'newbie' to PHP & MySQL - so please be patient and 'gentle'....

I have my MySQL Server set up and can access it by both PHPMyAdmin and via its 'native' GUI interface Workbench.

I can log into it with the 'root' username & associated password.
And I can use PHP to Connect to it with the 'root' username & associated password.

I then went on to add 2 new users to MySQL and I gave them Full Rights (as confirmed in both Workbench & PHPMyAdmin).

But when I attempt to Connect to the MySQL Server with those usernames, I get an error indicating that the username is not valid.
Access denied for user 'wpuser'@'localhost' (using password: YES)

Any suggestions/advice on what I need to do to correct this would be greatly appreciated.

Thanks,
JRB-Bldr
 
Hi. It sounds like the user is not fully set up. something like this is usually how you do it

Code:
create database mywp;

create user wpuser@localhost identified by 'somepassword';

grant all privileges on mywp.* to wpuser@localhost;

you'd need to do this as the mysql admin or a mysql user with sufficiently wide rights to grant privileges to others and create databases.
 
Thanks for the reply.

I thought that logging into the MySQL Workbench and accessing the instance of the MySQL Server with a root login - then creating users there with FULL RIGHTS to all databases/schemas, it would do the trick. Even PHPMyAdmin shows the new users with FULL RIGHTS.

Obviously something is still missing.

I then went into the Windows Command window and launched the MySQL Monitor.
But when I tried to enter the 'create user' line, I got an error message.
Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

I guess that I am not sure where/how to go from here.

Thanks,
JRB-Bldr





 
you need to login to mysql as the admin user for mysql (or a user with the right privileges).

ensure that you add the @localhost to the user name. unless you are not accessing the server on a local machine; in which case either you need to add a user at % or the relevant ip address.
 
Thanks for the reply.

The PHP code lines I was using was:
Code:
$user = "someusername";
$pwd = "associatedpassword";
$connection = mysql_connect("localhost",$user,$pwd) or die(mysql_error());

And the code worked just fine for the user: root
But it was failing for other users I created who had FULL RIGHTS

However I discovered that, unlike most Everything/Everywhere else, the MySQL Username is Case-Sensitive.

I always handle the Password as a Case-Sensitive value, but the Username seldom is.

Once I resolved that things began working.

Apparently, at least in a Windows environment, creating new users in either the MySQL Workbench or in PHPMyAdmin with FULL RIGHTS is sufficient as long as I remember to use Case-Sensitivity for BOTH login parameters.

Thanks for your help.
JRB-Bldr
 
mysql is quite case sensitive for things like databases and tables too (at least on the platforms that I use).
 
1) One could be the reason..
<?php
$connection = mysql_connect ('localhost', 'test', 'password')
or die ('<b>Could not connect: </b>' . mysql_error());
$result = mysql_select_db("gagalugc_stocks")
or die ('<b>Could not connect: </b>' . mysql_error());
?>

2) Didn't check for port when adding database make sure to specify host and port
(localhost:2083)

3) How about?
<?php
$connect = mysql_connect('localhost:2083','test','password');
if(!$connect){die('Could not reach database!');}
mysql_select_db("gagalugc_stocks", $connect)
?>

4) Try this, to find what error is occurred while connection
mysql_connect('localhost','test','password') or die(mysql_error());
mysql_select_db('gagalugc_stocks') or die(mysql_error());

Cheers!
[URL unfurl="true"]http://www.agileinfoways.com/technical-expertise/php-open-source-developments/php/[/url]
 
localhost:2083????

cPanel listens on port 2083

MySQL listens on port 3306 as default

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top