简体   繁体   中英

SQLSTATE[HY000] [1045] Access denied for user 'webapp'@'localhost' (using password: YES)

I'm trying to set up a php site that I currently had on virtual box on windows on a real Mac running Mavericks. I installed mysql with brew and created a generic phpinfo.php page that has

<?php
   phpinfo();
?>

That's working now. I checked to make sure MySql is running. When I try to login to my site, I get the error:

SQLSTATE[HY000] [1045] Access denied for user 'webapp'@'localhost' (using password: YES)

I'm pretty new to this whole setting up a site business but trying to learn how it works. Previously I just copied an image from someone that had it already running in vbox. So I checked to see who the users were in mysql, and I saw 4 users of root with this command

select User from mysql.user;

when I do show grants for 'root'@'localhost';, I see

GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION  

So where is this webapp user coming from for my website? Do I need to create a new user of webapp? Or can I change it to root for the website? Or is that a bad idea to use root?

Crystal, I just went through installing mySQL on Mavericks, and wound up going through a similar round-robin of permissions issues. The bottom line kept coming back to setting or knowing the password for the root user and ALSO being able to adjust privs in the files. I found these instructions for enabling the Root user for the OS. http://support.apple.com/kb/PH14281

Follow the instructions at that link to enable the root user.

Then, you have to stop mySQL, and run mysqld_safe --skip-grant-tables. When you do this, you will get several file permissions errors. Now that you have created a root user, you can log on as root and CHMOD those files. To log on as root in the terminal, just type "login", and it will ask for the login (root) and its password (the one you gave it when you enabled it).

Next, run mysqld_safe --skip-grant-tables again. if nothing happens Whoo hooo! open a NEW terminal window type mysql -u root (don't put -p there)

when you're logged in, run this: UPDATE mysql.user SET Password=PASSWORD('NewPass123') WHERE User='root';

You should get something like this: Query OK, 4 rows affected (0.01 sec) Rows matched: 4 Changed: 4 Warnings: 0

Next, run the following: flush privileges;

the response should be: Query OK, 0 rows affected (0.00 sec)

You can go back to the other terminal window and end it. Now, you know your root's password, and can set up other users, do grants, etc....

Once you're finished with this, it is recommended to go back into the Users/Groups settings and disable root again. I would not log onto the Mac as root - but rather just use that user for logging on in the terminal window when you need to. Then, when you're done, disable it.

I hope this helps. I've been going round in circles all day till I found how to enable the root user id for the OS.

--EDIT: I just realized I'd posted this on a different thread than I'd meant (had a lot of threads open)... however, since you can change the root password, then, use root to grant privs that webapp@localhost needs. "GRANT ALL PRIVILEGES ON . TO 'webapp'@'localhost' WITH GRANT OPTION; " (run that as root, and then flush privileges or restart the service)

This simply means your username or password are incorrect.

Try resetting your password, then use that one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM