I have read a number of questions discussing auth problems with MySql 8 however my problem persists. I removed ALL docker containers and created a new Laravel application, and here's what happened.
curl -s "https://laravel.build/example-app" | bash
The above command installed the application as expected.
cd my-app
./vendor/bin/sail up
The above command installed the docker images and spun them up. When I go to http://localhost I can see my application running, and I can access MySql from MySql Workbench using the default username (sail) and password (password).
php artisan migrate
The above command gives an error message as follows.
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known [...]
In Laravel's env file I updated the value of DB_HOST to 127.0.0.1, then tried the command again.
php artisan migrate
The above command gives a different error message this time around.
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client [...]
After Googling about I access MySql as root, and try to modify the authentication method for the sail user, as follows.
ALTER USER 'sail'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
The above command gives as error message as follows.
ERROR 1396 (HY000): Operation ALTER USER failed for 'sail'#'localhost'
I tried this from MySql Workbench, and from the command line of the MySql container. I tried flushing privileges, but that didn't help.
I then tried modifying the authentication method for the root user.
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
This worked fine. However, I then updated the user to root in my application, flushed privileges, and ran the migration again, only to receive the same error message.
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client [...]
The Laravel version is 8.48.1 and the MySql version is 8.0.25.
How can I access MySql from my application?
This turned out to be VERY simple.
When you are executing artisan commands with Sail, you need to preface them with 'sail'. The correct way to run the migration above is:
./vendor/bin/sail artisan migrate
More details here: https://laravel.com/docs/8.x/sail#executing-artisan-commands
Related
I cannot open the local instance in MySQL Workbench in Ubuntu 20.04 after installing the MySQL server. I searched for some similar topics here but these did not help.
Solution Found:
I've found the solutions for this problem. This was because of the MySQL Workbench couldn't store password in keychain and also because it failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'#'localhost'(using password:YES).
Use this command in the terminal: sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service.
The snap package is sandboxed as usual and is not by default allowed to access the service. MySQLWorkbench is blocked by AppArmor when we choose "Store in keychain" option. That's why we need to enter the command to allow the package to access the service.
The solution links that helped me:
MySQL Workbench not saving passwords in keychain
Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'#'localhost'(using password:YES)
All I need to do here is mainly type the following command in the terminal:
sudo snap connect mysql-workbench-community:password-manager-service :password-manager-service
Here, the snap package is sandboxed as usual and is not by default allowed to access the service. MySQLWorkbench is blocked by AppArmor when we choose "Store in keychain" option. That's why we need to enter the command to allow the package to access the service.
Try adding this step.
login to mysql in the terminal
execute this command
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
Check if this solved your problem <NOTE THE 'password' PART, CHANGE IT TO THE PASSWORD YOU WANT TO USE>
I tried all of the above steps, this one was the one that solved for me.
Make sure all the mentioned things working.
First check mysql is running by running below command:
sudo systemctl status mysql
If it's running make sure that your mysql username is root and password you are entering is correct. If still not working make sure you have given all the privileges to user "root".
If don't know how to set privileges read this article carefully.
https://docs.rackspace.com/support/how-to/install-mysql-server-on-the-ubuntu-operating-system/
I have pulled an existing project and am trying to get it to run locally (in Cloud9 IDE). However, I'm running into problems with connecting with the MySQL db.
There are some environment variables I believe to have set correctly. The password is kept empty, following the Cloud9 instructions.
I used mysql -u root -p and can then successfully access the MySQL db without submitting a password.
DB_NAME=c9
DB_USER=$C9_USER
DB_PASS=
DB_HOST=127.0.0.1
DB_DRIVER=mysql
DB_PORT=3306
When I now run npm run rollback or npm run migrate or anything else with the database, I receive an error:
Error: ER_ACCESS_DENIED_ERROR: Access denied for user
'$C9_USER'#'localhost' (using password: NO)
I then replaced $C9_USER in the environment variables with root, and ran npm run migrate. This time it worked and it didn't produce an error.
But I'm new to all this and not really sure if it is actually okay what I did. According to the Cloud9 manual I should be working with $C9_USER, so why is that not working for me? Also when I now run npm run rollback I now get another error (but maybe unrelated?):
Error: ER_ERROR_ON_RENAME: Error on rename of './c9/#sql-1827_4a' to
'./c9/sent_emails' (errno: 150)
I found out the problem. When I replace $C9_USER with the actual username, it works. The Cloud9 manual seems to suggest otherwise, but I needed to enter the actual values and not refer to the environment variable.
I'm using MySQL on windows (I wish I was using Mac, but due to some issues I'm using Bootcamp), and I've encountered a problem I think I've encountered before: the error that is written in the title. I think I might have solved this once before by erasing MySQL through the control panel and by erasing everything in the hidden folder, ProgramData, and MySQL from ProgramFiles, then reinstalling it. It is such a hassle and consumes a lot of time. It definitely isn't something I can do repeatedly to solve this problem if I get an error like this again and again.
The problem:
I simply ran this code on CMD after "cd"ing to the bin folder that contains mysql: mysql -u root -p PASSWORD but I get the error written in the title. Thus I can't login to mysql and run any lines to edit the database.
There are so many other topics like this in stackoverflow:
MySQL Error: : 'Access denied for user 'root'#'localhost'
Access Denied for User 'root'#'localhost' (using password: YES) - No Privileges?
https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
I tried implementing the solutions from the three links above. Many other advices advise to use the "sudo" command, which is not a windows command.
This is the line I get from implementing the solution given to me by dev.mysql.com (#3):
This is the line of code I ran in CMD:
mysqld --init-file=C:\\mysql-init.txt --defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini" --console
This is the code I ran to implement the solution in link #2:
mysqld --skip-grant-tables --skip-networking --console
and the code I get back:
Things to note:
Each time, I get this line of code back from the console:
[Warning]...[Server] CA certificate ca.pem is self signed.
In the first picture, this is the "ERROR" I get from the console: [ERROR]...[Server] unknown variable 'defaults-file="C:\ProgramData\MySQL\MySQL Server 8.0\my.ini'
In the second picture, this is the "ERROR" I get from the console: [ERROR] TCP/IP --shared memory, or --named-pipe should be configured on NT OS
This is the line of code I would put in in mysql-init.txt: ALTER USER 'root'#'localhost' IDENTIFIED BY 'PASSWORDHERE';
or this: INSERT INTO mysql.user (Host, User, Password) VALUES ('%', 'root', password('YOURPASSWORD'));
GRANT ALL ON *.* TO 'root'#'%' WITH GRANT OPTION;
I installed MySQL through the installation wizard.
Q. How did I encounter this error?:
A. I was experimenting on a project for a back-end Spring Boot project that uses JPA and JDBC combined. I got errors telling me that no datasource could be configured.
Q.How did my root password get reset?
A.I think they got reset because of JPA's datasource autoconfiguration. I didn't touch any of mysql's settings myself. Something I did on Spring Boot and its automatic configuration to localhost must have reset the password.
I will say that uninstall your MySQL and again install it with a new instance but not like just uninstall it from the control panel that's why you are facing the same error every time. I already answered here in detail that how to remove properly so no error will come by creating a new instance.
For anyone encountering this issue after they initialized their mysql server with following command:
mysqld --initialize
Look out for the last output of the process, it should say something like this:
[Note] [MY-010454] [Server] A temporary password is generated for root#localhost: password12345
there is your temporary password to log in.
Hi I am trying to setup Owncloud with an external MySQL DB.
In MySQL server - I have changed bind-address= 0.0.0.0 , created a user and granted , flushed privileges.
Now i am able to connect to MySQL from CMD in Owncloud server.
When I try to setup getting an error
" Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1044] Access denied for user ‘oc_root2’#’%’ to database ‘owncloud’ "
Can some one please help.
You should consider using Nextcloud. This is more actively maintained, fully open source and has more features. Setting up Nextcloud via the command line works fine for me. I suggest that you use the setup-nextcloud.php script and everything should be automatic.
I've installed XAMPP. I had put up security barriers but as time went by I forgot my credentials and could no longer access the MySQL server through phpMyAdmin. I keep having the following error trying to enter phpMyAdmin:
1045 Cannot log in to the MySQL server.
I've edited C:\xampp\phpMyAdmin\config.inc to change my passwords but I had no success afterwards. I've altered the bit:
Authentication method (config, http or cookie based)
$cfg['Servers'][$i]['user'] = 'xxxxx' ;
$cfg['Servers'][$i]['password'] = 'yyyy' ;
I've run the MySQL resetroot batch file without success.
I've changed the default ports on my Apache and Mysql at the localhost a couple weeks ago and now I can't access mysql.exe.
Can't connect to MYSQL service on 'localhost'(10061).
How can I change the default localhost port?
Did you take a look here?
After installing a local server and trying to access phpMyAdmin, you could possibly encounter the error: #1045 Access Denied for user 'root'#'localhost' (using password: YES).
If root#localhost wasn't granted the necessary rights to access the database or you provided the wrong password, you will then encounter this error.
Following this tutorial will help guide you on bypassing this error, for any local host server using phpMyAdmin.