Laravel Valet MySQL错误:指定为定义者的用户不存在

时间:2018-07-26 23:00:35

标签: php mysql laravel valet

在重新安装Laravel并运行Valet的情况下,应用可以正常运行。

问题正在尝试使用MySQL建立数据库。我可以创建一个数据库,告诉MySQL使用它,但是不能做任何事情:

mysql> create database foobar;
Query OK, 1 row affected (0.09 sec)

mysql> use foobar;
Database changed

mysql> show tables;
ERROR 1449 (HY000): The user specified as a definer ('mysql.infoschema'@'localhost') does not exist

如果我尝试php artisan migrate,我将得到以下信息:

PDOException  : SQLSTATE[HY000] [2006] MySQL server has gone away

  at /Users/isaacfennell/Sites/anything/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
    64|         if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
    65|             return new PDOConnection($dsn, $username, $password, $options);
    66|         }
    67|
  > 68|         return new PDO($dsn, $username, $password, $options);
    69|     }
    70|
    71|     /**
    72|      * Determine if the connection is persistent.

  Exception trace:

  1   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=anything", "root", "", [])
      /Users/isaacfennell/Sites/anything/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   Illuminate\Database\Connectors\Connector::createPdoConnection("mysql:host=127.0.0.1;port=3306;dbname=anything", "root", "", [])
      /Users/isaacfennell/Sites/anything/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:98

  Please use the argument -v to see more details.

我是Laravel和MySQL的新手,不知道如何解决这个问题-这是怎么回事?谢谢

3 个答案:

答案 0 :(得分:1)

解决了第一个问题:

运行mysql_upgrade -u root

在这里找到:Mysql Error:The user specified as a definer ('mysql.infoschema'@'localhost') does not exist' when trying to dump tablespaces

运行php artisan migrate的情况下,仍然会产生与上述相同的错误输出…

答案 1 :(得分:0)

如果您使用的是Mac,请在终端中输入:

composer global require "laravel/installer"(enter)
nano .bash_profile(enter)

按下i按钮,以便您可以写

export PATH="$PATH:$HOME/.composer/vender/bin"

alt+commandenterx按钮退出

然后,打开XAMPP,单击“常规”,单击“打开终端”,单击终端并键入:

pwd (enter)
cd space .. (enter)
cd opt/ 
cd lampp (even if you are using xampp)
cd htdocs
cd ur laravel folder name
php artisan migrate

https://www.youtube.com/watch?v=BUFyKk-GrvI&t=18s

我希望它能起作用

答案 2 :(得分:-1)

我也遇到了第二个问题,我通过创建和使用新的MySQL用户而不是使用root来解决了这个问题。

    mysql> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'newpassword';
    mysql> GRANT ALL PRIVILEGES ON anything.* TO 'newuser'@'localhost';

请不要忘记在应用程序的.env文件中更新DB_USERNAMEDB_PASSWORD,您可以在根目录中找到它们。