DEV Community

Vicente G. Reyes
Vicente G. Reyes

Posted on • Edited on

php artisan migrate

I was asked to create a CRUD APP with Laravel and Mysql from a potential employer but I'm getting an error when I run:

php artisan migrate
I've read all links on the first page of Google and Duckduckgo already but I couldn't find the answer to my problem.

The errors when I run php artisan migrate is:

Illuminate\Database\QueryException  : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client (SQL: select * from information_schema.tables where table_schema = Laravel-tasks and table_name = migrations)

at /Users/my_username/PHP/todo/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make this exception a
662| // lot more helpful to the developer instead of just the database's errors.
663| catch (Exception $e) {

664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|

Exception trace:

1 PDOException::("PDO::__construct(): The server requested authentication method unknown to the client [caching_sha2_password]")
/Users/my_username/PHP/todo/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

2 PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=Laravel-tasks", "root", "YGM4QV6kWnjz3uN!", [])
/Users/my_username/PHP/todo/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

This is the command line I executed inside my project folder

php artisan make:migration create_tasks_table

This is the code on the create_tasks_table.php:


bigIncrements('id');
            $table->string('title');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('tasks');
    }
}

The Database on the .env is:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Laravel-tasks
DB_USERNAME=root
DB_PASSWORD=*****

Hoping for your experienced responses!

Cheers!

Top comments (9)

Collapse
 
herivgs profile image
herivgs • Edited

I'm assuming that you are running MYSQL Version 8... So, you are having issues with passsword encrypting "caching_sha2_password" that is configured by default in Mysql8 and Laravel does not support it well.

There's two way that you can fix that:

  1. The easy way is to downgrade to 5.x version
  2. Modify the encryptation of the user's password with: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password'
Collapse
 
mhrabiee profile image
Mohammad Hossein Rabiee

Great workaround dude!

Collapse
 
highcenburg profile image
Vicente G. Reyes

On my MAMP's preferences, MySQL is using 5.7.25.

Collapse
 
herivgs profile image
herivgs

did you tried the second one?

Modify the encryptation of the user's password with:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password'

Thread Thread
 
highcenburg profile image
Vicente G. Reyes

Yup.

zsh: command not found: ALTER
 
highcenburg profile image
Vicente G. Reyes

Thanks

Thread Thread
 
elkalash profile image
Nahael Mele

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password'

Did this worked for you ?

Thread Thread
 
victormreyes profile image
victor-m-reyes

Hi Nahael,

It worked for me!, thanks a lot.

Collapse
 
agustinguanipa profile image
Carlos Agustin Guanipa Alvarez

Did you solve the issue? I am having the same problem with same specs.