Have you defined your database connection in your .env file and are those the same credentials that you're using when attempting to log back in?
mysql access denied
after a successful php artisan migrate, I exited mysql in terminal and tried to log back into mysql of my app using my default system password, and I kept getting the error below.
sudo mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
I getting this in both Laravel apps where only one Laravel app has its db username as "root"
@lbecket please how do you mean by database connection? I have already set a db, db-username and password. does that mean if I want to log into my sql, I will now use the password I set in .env file?
@icetechy Your database connection is defined in your .env file and this is what gets defined when you migrate your database. It should look something like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myDatabaseName
DB_USERNAME=root
DB_PASSWORD=password
@lbecket yes its like this but I changed the credentials of DB_HOST= localhost DB_DATABASE=myfirstdb DB_USERNAME=myfusername DB_PASSWORD=gQ6oF5tN8yL9yF8l
@icetechy See my other comment about making sure that you're entering a command in the terminal that will prompt for your password.
@icetechy As I think more about this, I'm pretty sure that your migration would have failed if you hadn't first created the database and then properly set these parameters to match the DB credentials. Regardless, it still begs the question of whether you're attempting to login from the terminal with these same values.
Are you setting a password when logging in again? For example mysql -u root -p would prompt you to enter your PW
@lbecket I am using 'sudo mysql" which is promoting me to enter a password. I usually use my system password to login which logs in successfully.
@icetechy are you including the -u flag? You want to make sure that it's the correct user
@lbecket no I am not including the -u flag. normally I just use this "sudo mysql" enter my system password and I get logged in.
@lbecket even after using mysql -u root -p I still get the error below:
Access denied for user 'root'@'localhost' (using password: YES)
The error suggests that you're attempting to login to MySQL with user root and you've mentioned user myfusername in the .env. Does this database have a user named root?
@lbecket the database with the username root is another app not this one.
@icetechy Wait... you're trying to log in to a different database from the one that's associated with this app? I can't say that I understand the relevance of the migration then. Regardless, the only reason that I can think of for this error is that you aren't providing the correct password for the user root.
@lbecket I have two db for two different apps, only one has a db_name "root". how the two different apps suddenly had two same db-names is what I don't understand. However, is there a way I can drop the databases and start all over again?
I have two db for two different apps, only one has a db_name "root"
Is it a different instance of MySql?
@jlrdw I don't know what you mean. I'm a newbie to this.
@icetechy it means do you have mysql installed twice.
@jlrdw nope but I just deleted the whole mysql. I initally used home-brew to install the sql but this time around I am using the mysql dmg file. This denial issue happened after someone in another thread asked me to use this ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_USER_PASSWORD';
@icetechy did you replace 'NEW_USER_PASSWORD' with actual password?
@jlrdw I can't really remember the password I used but I did change the 'NEW_USER_PASSWORD' to an actual password.
@icetechy I think this is starting to make sense. You've changed the password to something that you don't remember, so it stands to reason that you're not able to log back in. It also sounds like you haven't yet populated this database with any actual data, so my advice would be to start with a fresh installation. That seems like the path of least resistance at this point.
Don't enter your mysql password, especially for root, in the command itself, or it will be stored in your shell history. Just leave the -p option by itself and mysql will prompt for a password.
@icetechy If you tried to enter mysql using command line without password by typing
mysql -uroot
Are you able to enter ?
This one solved it for me: https://gist.github.com/vitorbritto/0555879fe4414d18569d Remember to delete the files etc
Please or to participate in this conversation.