SitePoint Sponsor

User Tag List

Results 1 to 15 of 15
  1. #1
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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.

  3. #3
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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 Access denied; you need (at least one of) the RELOAD privilege(s) for this operation 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.

  5. #5
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    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?)

  7. #7
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  8. #8
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  9. #9
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that. Yes, using the terminal I was able to log in.

    What would be the next step?

    Thanks

    aej71_le

  10. #10
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  11. #11
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  12. #12
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  13. #13
    Non-Member yadavarun's Avatar
    Join Date
    Mar 2011
    Posts
    7
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  14. #14
    SitePoint Member
    Join Date
    Apr 2011
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for getting back to me - I'll reinstall and give it another go.

  15. #15
    SitePoint Zealot
    Join Date
    Apr 2011
    Posts
    109
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aej71_le View Post
    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...


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •