Laravel Migration stalls and doesn't do anythi

2019-05-06 03:30发布

问题:

Just went through all the steps listed on the Laravel site to install and get up and running for MacOS HighSierra. I currently have Composer, Homebrew, valet, PHP 7.2.8, MySQL version 8.0.11 and Laravel 5.6.28 installed. I can create a new project by doing the Laravel new blog command and not have any problems. Also when I go to my browser I can see current project I just created or am working on. I can run the valet list command and so I know its running/working. I also can create a migration and have it show up in my project as well by running the php artisan make:migration test_test_test.

My PATH also has ~/.composer/vendor/bin in it as well.

my .env file look like such

APP_NAME=Laravel
APP_ENV=local
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog        
DB_USERNAME=root
DB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
SESSION_LIFETIME=120
QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1 
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp 
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

I run the php artisan migrate -vvv command and it runs and stalls/hangs up with no output. I have to ctl-c to get out of it. tried the -v /-vv as well, did the same thing.

I created a database named blog and even add a table test manually to make sure that the database was working/running.

Update

Went ahead and uninstall MySQL and reinstall it. I was able to get the php artisan migrate -v command to run and am getting this error.

now I'm getting this error.

MacBook-Pro:anything computername$ php artisan migrate -v

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

at /Users/computername/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:

Created a router and view that connects to a table that I creates to see if I would be able to access the database variables and print them out. On return I got this error.

Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

回答1:

I myself had this problem and getting the error Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

This is how i fixed it:

I logged into mysql as root user like so mysql –uroot –p and entered my password

You can get a list of the users that are on the server by typing this SELECT User, Host FROM mysql.user;

Make sure that you see the user you are trying to connect to the database from your .env file. You will need to altered the current user to use the caching_sha2_password that is required in the lasted version of mysql.

Here is that command.

ALTER USER `username`@`localhost` IDENTIFIED WITH caching_sha2_password BY 'password';

While still logged in as root user you need to run this command to allow for your user to do the needed tasks that are allowed for an php artisan migrate to happen. Ex: CREATE, DROP, ALTER, DELETE and such.

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost';

If this doesn’t work you can also pick and choose what commands you want to allow instead of giving them complete access.

GRANT SELECT, INSERT ON *.* TO 'someuser'@'somehost';

Hope this helps~



回答2:

Server has gone away is a MySql error, check this link

Check that your mysql service is indeed running and afterwards, that you've got the right credentials on you .env file

About the 'initial error' on migrations, we need to see what's in the migration code.

Edit: Since the migrations are Laravel's default, then the issue probably lies upon the connection between Laravel and the database.

To confirm this:

  1. Create a database manually;
  2. Create a table and place a row in it;
  3. Create a route that returns DB::statement('select * from tablejustcreated');

Make the request to that route and if it freezes up, boom, it's the connection and most likely, .env file credentials (username and password, host, port).



回答3:

It is a known bug in PHP 7.2.8. Downgrade to PHP 7.2.7 until it is fixed.

I hit the same problem when I upgraded from PHP 7.2.7 to PHP 7.2.8.

See https://bugs.php.net/bug.php?id=76651



回答4:

Many thanks to @poohhbear and everyone else for helping me get this fixed.

What actually worked for me was:

ALTER USER 'myusername'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mypassword';

...presumably because the new MySQL defaulted to caching_sha2_password and PHP didn't know how to handle that.



回答5:

try this php artisan migrate --force [https://laravel.com/docs/5.6/migrations] this a documentation of migrate i think could be useful



回答6:

delete all table in db blog and run this artisan command

php artisan migrate

this build tables in db