Laravel Valet MySQL error: user specified as definer does not exist

1.4k Views Asked by At

On a fresh Laravel install, running Valet, app works fine.

Problem is trying to set up a database, using MySQL. I can create a database, tell MySQL to use it, but can't do anything with it:

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

If I try php artisan migrate i get the following:

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.

I'm new to Laravel and MySQL and can't figure out how to solve this - what's going on here? Thanks

3

There are 3 best solutions below

0
On

Solved the first issue:

Run mysql_upgrade -u root

Found here: Mysql Error:The user specified as a definer ('mysql.infoschema'@'localhost') does not exist' when trying to dump tablespaces

BUT running php artisan migrate still gives the same error output as above…

0
On

I also ran into the second problem and I solved it by creating and using a new MySQL user instead of using root.

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

Don't forget to update the DB_USERNAMEand DB_PASSWORD in the .env file of your application, which you can find in the root directory.

0
On

If you are using mac, in terminal write:

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

press i button so you will able to write

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

press alt+command and enter press x button to exit

Then, open your XAMPP, click general, click open terminal, click terminal and type:

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

I hope it will work