Do you have the correct config for the database? It looks like you're using the wrong credentials or a user that doesn't have access to the database you try to use!
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
I'm trying to connect my laravel to mysql, but when I do php artisan migrate it says:
SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client
I'm using laravel v5.6.26 MYSQL 8.0.11
Check your my.cnf file for your mysql configuration. Make sure it has this in the mysqld section:
[mysqld]
default_authentication_plugin= mysql_native_password
Another value to check is to make sure
old_passwords=0;
is not 1.
@Cronix I added both of those, and the 2054 error went away, and was replaced by:
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it. (SQL: select * from information_schema.tables where...
here's whats in my database.php
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
and here's whats in my env
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=goldencabinet DB_USERNAME=root DB_PASSWORD=
I assumed you've restarted the server, and you're sure it's running?
Can you connect to it via the commandline or another app like Sequel Pro/Navicat/PhpMyAdmin/etc?
Do you have a firewall, and is it blocking port 3306?
How was this mysql server set up? Just seems strange you're running into these issues.
You can also try changing DB_HOST=localhost in .env
Hi @Cronix
Restarted the mysql server in services panel Yes I can connect to mysql through command line Firewall - turned off windows defender and antivirus and no change Setup was done by downloading mysql 8.0 and running it with all defaults. No difference after changing dbhost to local host.
Any other ideas?
Thanks for the help so far.
If you can login via command line you may be able to do a sql query to see the root@your-address.
i.e. mysql> select user();
+----------------+
| user() |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.41 sec)
For MySQL 8.0.x, add
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
to your database.php file as below:
// database.php
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => env( 'DB_HOST', '127.0.0.1' ),
'port' => env( 'DB_PORT', '3306' ),
'database' => env( 'DB_DATABASE', 'forge' ),
'username' => env( 'DB_USERNAME', 'forge' ),
'password' => env( 'DB_PASSWORD', '' ),
'unix_socket' => env( 'DB_SOCKET', '' ),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
],
It fixed it for me.
Please or to participate in this conversation.