• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Help connecting to Mysql Database

NuAndy

New Pleskian
So my problem has had me bashing my head against a wall trying to figure out what is going on, I'm hoping somebody here might know what is going on.

Basically I am trying to access mysql so that users who go to my site can register an account and their information will be put into a database (simple enough). I am using a homemade php script for this.

The Problem: When I try to execute the registration process I recieve this error:

Access denied for user 'root'@'localhost' (using password: NO)

Now my connection file for establishing the connection to the database does not have any of the above information in it. Why would my script attempt to connect to the database using this information when I have clearly laid out the host, username, and password that it should be using to connect to the database (aka: the information that corresponds to the database and user I created in my plesk panel)?

I understand that the root is not allowed access to mysql for security reasons, but I'm just trying to figure out why I'm getting this error and how I can fix it. Maybe this is a very simple fix, as this is my first time hosting on a virtual private server, but right now I'm stumped.

Any help is much appreciated!
 
On the face of it, my guess is that there is a tiny error in the php code that you are using.

I'm not 100% sure, but I would not be surprised to find that root@localhost is the default user that mysql assumes when no username is specified when a database connection is attempted ('root' being the default username for the mysql admin login in a non-plesk environment -- there is no direct connection between the 'root' linux user and the 'root' mysql user -- they can have different passwords and indeed the admin user for mysql doesn't need to be called 'root' - it is changed to 'admin' when plesk is installed, for example).

If you are using a third-party library to connect to Mysql rather than PHP's built-in library, try a different library, or try using php's built-in stuff.
 
PHP built in Library?

Thanks for the response Faris!

Okay so I am not using any kind of library (I assume this is why my script defaults to root using password NO). It should be noted that I had a friend helping me with the php on the site but is no longer able to volunteer his time on the project, thus I am left to my own resources to get this site up and running.

I don't really know anything about the process of setting up a library, if somebody could direct me to a link or tutorial that could help me with this I would really appreciate it. I believe that we are using the most recent version of PHP as my friend who wrote the script does php for a living (I assume that professional environments would use the most up to date version).

Thank You!
 
PS:

I may be using a PHP library if it came with my server, but I did not actively set one up. I assumed that the server would come with the ability to read php and I think this may be why the script is not working.

Any help is much appreciated!
 
Well, no, I don't think you need to worry much.

By "library" I just meant an additional bit of code or collection of code that is sometimes used to connect php to mysql. Sometimes these things make it easier to connect, or to connect to a non-mysql db without chaging your code. Maybe "library" is the wrong word. I'm not a pro programmer so sometimes I use the wrong terms for some things.

But php has built in functions to connect to a mysql database. And I guess that's what your code is doing.
I just get the impression that it might not be doing it correctly -- e.g. not sending a username when it should.

Take a look here: http://php.net/manual/en/ref.mysql.php
I imagine something is going wrong at the mysql_connect stage. Maybe the variables holding the username and password are not being sent, or the configuration file containing them is not being included. Or something. It could be anything.
 
Thanks for the help, I'm going to keep working on this and I'll post my results here. I'm thinking that there is just some small error I'm overlooking so I'm just going to take a break from the script and come back to it with a clear head. Again thanks for the help!
 
sure enough a very small error, when I was linking to the connection file I was not including the proper path *facepalm* thanks for the assistance nonetheless!
 
Back
Top