如何使MySql 8与laravel一起运行? [英] How to get MySql 8 to run with laravel?

查看:312
本文介绍了如何使MySql 8与laravel一起运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难使MySQL 8正常工作.这是每次我尝试php artisan migrate时都会出现的错误.到目前为止,我只安装了一次MySQL,因为我不想再为发生的事情而伤脑筋.我已经从其他可能的答案中编辑了database.php,但这似乎也不起作用.我看到一个可能的答案,这是因为MySQL 8对root密码进行了sha256加密,这就是为什么我想回到MySQL 5.7,而我所查找的与laravel配合得很好.不过,我希望保持软件包最新,并仅在我可以使它与laravel一起使用时才保留MySQL 8.

I'm having difficulty getting MySQL 8 to work. This is the error that appears everytime I attempt a php artisan migrate. I've reinstalled MySQL only once so far because I didn't want to hurt my head anymore on what was going on. I've edited the database.php from other possible answers, but that also doesn't seem to work. I saw a possible answer that it's because of MySQL 8's sha256 encryption of the root password, which is why I want to go back to MySQL 5.7 which I've looked up works with laravel just fine. Though, I want to keep the packages up to date and keep MySQL 8 only if i can get it to work with laravel.

PHP 7.2

如何使MySQL 8与Laravel一起使用?

How do I get MySQL 8 to work with Laravel?

 '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' => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'version' => 8,
            'modes' => [
                'ONLY_FULL_GROUP_BY',
                'STRICT_TRANS_TABLES',
                'NO_ZERO_IN_DATE',
                'NO_ZERO_DATE',
                'ERROR_FOR_DIVISION_BY_ZERO',
                'NO_ENGINE_SUBSTITUTION',
            ],
        ],

``

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_tut and table_name = migrations)

  at /Users/home/Projects/laravel_tut/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/home/Projects/laravel_tut/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=laravel_tut", "root", "fdgkadgaf9g7ayaig9fgy9ad8fgu9adfg9adg", [])
      /Users/home/Projects/laravel_tut/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:70

更新我要修复的其他修复程序: 全新安装MySQL后,我在设置中选择了否(使用旧式加密,而不是SHA加密)来加密密码,并且它开始与Laravel一起使用而没有任何问题-只需使用一个长而牢固的密码即可. 安装步骤参考: https: //www.percona.com/blog/wp-content/uploads/2018/05/Installing-MySQL-8.0-on-Ubuntu-2.png

UPDATE ANOTHER FIX I DID TO FIX THIS: With a fresh install of MySQL, i selected NO for encrypting passwords in the set up ( using legacy encryption, not the SHA encryption ) and it started to work with Laravel without any problems - Just use a long and strong password. reference of the installation step: https://www.percona.com/blog/wp-content/uploads/2018/05/Installing-MySQL-8.0-on-Ubuntu-2.png

推荐答案

由于PHP无法理解caching_sha2_password,请将用户设置回mysql_native_password:

Since PHP doesn't understand caching_sha2_password, set the user back to mysql_native_password:

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

这篇关于如何使MySql 8与laravel一起运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆