Difficulties connecting to database

In chapter 4 I have placed the file index.php in the directory connect and have amended the following line in order to connect to the sql server on my computer: mysqli_connect(‘localhost’, ‘root’, ‘mypassword’);

The issue: adding ‘mypassword’ won’t open a connection to the database server. I have to substitute the password ‘root’ to open a connection.

However, I changed the password from ‘root’ as instructed in Ch. 1 Installation. I have checked that ‘mypassword’ is correct by using the terminal and establishing a connection that way.

Could you advise? I am am Apple user using MAMP.
thanks in advance

It sounds as if you have not altered the password for root from ‘root’ to ‘mypassword’.

You might think you have, but it sounds as of you have not run the command FLUSH PRIVILEGES, which causes these privileges to take effect.

It might be that, it is a common pitfall.

Thanks for this. Could you point me in the right direction? I get the following error message:

mysqladmin flush-privileges

mysqladmin: reload failed; error: ‘Access denied; you need (at least one of) the RELOAD privilege(s) for this operation’

aej71_le

Well as my answer may well be convoluted because I have never gotten myself into this situation I can only refer you to the rather obvious [google]Access denied; you need (at least one of) the RELOAD privilege(s) for this operation[/google] search.

If root/root does not give you access to the DATABASE named mysql (where all the privileges are managed ) then you need to do some hunting.

If you are using PHPMyAdmin (PMA) then check on the top of the page and see which user you are logged in as - it might be as simple as editing your PMA config file.

No I’m not using ‘PHPMYADMIN’ and the link didn’t bring up any useful search results. I purchased the Sitepoint book as it is for beginners with good html and css knowledge. I have followed the instructions carefully but then came across my initial problem, namely:

In chapter 4 I have placed the file index.php in the directory connect and have amended the following line in order to connect to the sql server on my computer: mysqli_connect(‘localhost’, ‘root’, ‘mypassword’);

The issue: adding ‘mypassword’ won’t open a connection to the database server. I have to substitute the password ‘root’ to open a connection.

However, I changed the password from ‘root’ as instructed in Ch. 1 Installation. I have checked that ‘mypassword’ is correct by using the terminal and establishing a connection that way.

Could you advise? I am am Apple user using MAMP.

Sorry I cannot help you any more then, I do not possess that book and do not run an Apple computer.

Someone else on here will not doubt be able to look that up for you and tell you where you are going wrong.

(you did restart the server after changing the main root password and running “flush priviliges”, I guess?)

Thanks for all your help. Yes I did restart the server. The flush-privileges - called from the terminal - just produced an ‘access denied’ message. I located MYPHPADMIN, changed the root password there and then was able to get the php script to connect to the MYSQL database. However, I now can’t access http://localhost:8888/MAMP/?language=English - I get a message that I can’t access the MYSQL server. It is as though there are two passwords in operation. As a beginner I don’t have enough knowledge to troubleshoot properly. Thank you

Hi aej71_le,

Sorry to hear you’re having trouble with the instructions in my book!

If you have shut down and restarted MAMP, that’s going to do the same as the flush-privileges command, so I wouldn’t worry about that.

Given that you can only connect with the password ‘mypassword’ from the Terminal, and only connect with the password ‘root’ from PHP, it’s sounding a lot like you have more than one MySQL server running on your system. Can you try this experiment for me?

  1. Quit the MAMP application.
  2. Open Terminal.
  3. Try to connect to MySQL (using the ‘mypassword’ password that usually works there).

If you are able to connect to MySQL, you’ll know for sure that what you’re talking to from the Terminal isn’t the MySQL server built into MAMP, but another copy of MySQL that you have installed on your computer by some other means.

Let me know what you discover, and we’ll take it from there.

Thanks for that. Yes, using the terminal I was able to log in.

What would be the next step?

Thanks

aej71_le

aej71_le,

What I’d suggest is just to carry on using MAMP with the “root” password. MAMP doesn’t allow connections to its built-in MySQL server from the outside world, so you aren’t at risk by using the default password.

If you really want to change the root password for the MySQL server built into MAMP, I remember finding instructions on the official MAMP support forums.

Hi, Unfortunately I can’t access MAMP any more - see posts on 5 April. I get the following error message:

/Applications/MAMP/Library/bin/mysqlcheck: Got error: 1045: Access denied for user ‘root’@‘localhost’ (using password: YES) when trying to connect

This was after changing my password in myphpadmin to ‘mypassword’ in an attempt to synchronise it.

What would you recommend? I’d love to carry on using your book - which is well written and is intended for beginners with advanced css and html - but I need to sort out the password issue. Would you delete MAMP and reinstall it?
I don’t want to have to buy another book.

Thanks

At this stage I’d recommend deleting and reinstalling MAMP from scratch. As you’ve discovered, changing its MySQL root password is more trouble than it’s worth. :slight_smile:

I have managed to solve part of the problem by copying my data source file from My Documents/My Data Sources to a server location and using that for the database connection.

This works with the ‘sa’ account but I’m not sure yet if it works with windows authentication.

Thanks for getting back to me - I’ll reinstall and give it another go.

I had these same problems… Part of the problem is that, Kevin tells you to change the password in one spot, but does not tell you about the other 3-4 spots that need changes also… Your best bet… If you are only using it on your local computer. DONT CHANGE the password. Leave it as root/root… Also, if you are using MAMP, you either have to store your .php where MAMP wants them stored, or you have to tell MAMP where to find them, by going into the Preferences on the MAMP Program Icon, Apache

Also note, that to delete MAMP and all its changes… simply drag the folder to the trash and empty…