Originally had a project that worked with MySQL(5.7.25x64 if it matters).
Now I need to deploy this project on another server, with MariaDB (10.4.11-MariaDB)
After composer install trying php artisan migrate but catch exception
Illuminate\Database\QueryException : SQLSTATE[HY000] [2006] MySQL server has gone away (SQL: select * from information_schema.tables where table_schema = admin_testtable and table_name = migrations and table_type = 'BASE TABLE')
laravel 6.10.1
MariaDB 10.4.11
PHP 7.3.13
Centos8
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=admin_testtable //(i can't remove 'admin_' in name. the DB is created and exists)
DB_USERNAME=username
DB_PASSWORD=password
php artisan optimize:clear, php artisan config:cache, composer dump-autoload, restart server - doesn't help (just in case)
Edit your my.cnf file
max_allowed_packet=64M // set 128M if required
On Windows this file is located at: "C:\ProgramData\MySQL\MySQL Server 5.6"
On Linux (Ubuntu): /etc/mysql
Reload your mysql service after editing.
Related
I'm working on a small project using Laravel 9 / Laravel Sail. I have a weird error. my application queries works fine I can select, update, insert with no problem using Eloquent also. Everything is good.
Now I try to created a new migration and I try to push the migration using the usual php arisan migrate I'm getting an error message :
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for mysql failed: Temporary failure in name resolution (SQL: select * from information_schema.tables where table_schema = project and table_name = migrations and table_type = 'BASE TABLE')
But by application works fine its connected to the database as I'm inserting and selecting, updating
the problem is just when I try to migrate which is weird.
my env :
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=project
DB_USERNAME=username
DB_PASSWORD=password
If you're using Laravel Sail, you should run:
sail artisan migrate
instead of:
php artisan migrate
you can try set DB_HOST=localhost
or it can be DB_HOST=0.0.0.0
next execute the
php artisan config:clear
this command will help you, clear the cached config
then you can run your migration
php arisan migrate
I'm trying to make a project using Laravel and Sail but I'm getting errors when I'm trying to migrate or do anything related to the project's database (for example, seeding).
More specifically, when using artisan sail migrate or anything related, I'm getting the following errors:
When DB_HOST=localhost in my .env file:
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
When DB_HOST=127.0.0.1 in my .env file:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = noway and table_name = migrations and table_type = 'BASE TABLE')
What I've tried:
changing the DB_HOST to localhost and 127.0.0.1 (most common answer online, no succes)
making sure SQL is running
clearing cache for sail artisan migrate
./vendor/bin/sail down --rmi all -v to remove all images and volumes
changing username and password and putting them between '' or ""
None of the above have been of succes.
did you run ./vendor/bin/sail up after creating and setting .env ? if not please execute ./vendor/bin/sail down --rmi all -v to remove all images and volumes and then just ran ./vendor/bin/sail up to recreate the images and volumes.
Also as per laravel docs https://laravel.com/docs/8.x/sail you can connect to db by setting env DB_HOST to mysql
T had the same problem with pretty much the same conditions:
-I started with a laravel project then moved it to sail
the way I solved this was by adding an entry DB_PORT=3306 in the .env file and changed DB_HOST=localhost to DB_HOST=mysql as described in laravel docs : https://laravel.com/docs/8.x/sail#mysql
don't forget to check the new credentials that sail uses by default
When i run the command php artisan migrate it gives me this error:
SQLSTATE[08006] [7] could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432? (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
In as much as i am using a database.sqlite file for my database
My .env file:
DB_CONNECTION=sqlite
The problem was fixed by doing the following:
I added the path for my database file in my .env, then it looked like this below
DB_CONNECTION=sqlite
DB_DATABASE='database/database.sqlite'
Then I cleared my cache using php artisan config:cache
Then I ran php artisan migrate and it worked!
when typing the command php artisan migrate, it is giving me an error:
Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown
database 'proj' (SQL: select * from information_schema.tables where
table_schema = proj and table_name = migrations and table_type = 'BASE
TABLE')
Although, i edited the .env file and i had created the database proj and restart the cmd and also i tried
php artisan config:cache
and similar commands but still not working
view error image
phpmyadmin view
.env file view
This means that you don't have this database created. First create the database and after run: php artisan migrate:fresh to create the tables.
By the screenshots you have uploaded, you have many servers. Check the port of the server mysql and change the port on the .env file. This will work.
Open the .env file and edit:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= // db Name
DB_USERNAME= // db Username
DB_PASSWORD= // db Password
Run below commands:
php artisan config:cache
php artisan migrate
I hope this will help you
I deleted the migrations table from a Laravel 5.4 database named laravel. When I run php artisan migrate:install, I get this error:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations)
I deleted and recreated the database. I also ran composer update. No luck. I can run the command in phpMyAdmin and create the table manually.
This problem sometimes also manifests itself with similar 2002 errors:
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations and table_type = 'BASE TABLE')
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known
(SQL: select * from information_schema.tables where table_schema = laravel
and table_name = migrations and table_type = 'BASE TABLE')
If you are using localhost as your DATABASE_HOST in the .env file, change it to 127.0.0.1, then run php artisan config:clear and now try php artisan migrate:install again.
Here's what I recommend for .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
Then in Database.php add folder location:
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
Finally, try:
php artisan config:clear
php artisan migrate:install
I fixed this issue by setting environment variables in .env file:
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
Actually I just changed from DB_HOST=127.0.0.1 to DB_HOST=mysql.
If you are using MAMP Pro (not always necessary for the free version of MAMP) then the best thing to do is add this to your .env file:
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
This assumes your MAMP installation is at /Applications/MAMP of course (the default).
Credit: A comment in this question by #Uncoke
I am using MAMP on macOS and after editing localhost to 127.0.0.1 and port to 8888 this problem fixed by adding the following
'unix_socket' => env('DB_SOCKET', '/Applications/MAMP/tmp/mysql/mysql.sock'),
to config/database.php file.
For mac users, add this to your .env file
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
In some cases this may happen because mysql server is not running. It happened to me using Laravel 5.7 and restarting mysql server solved it. For ubuntu check the status of mysql server service mysql status. You can restart mysql server using command service mysql restart
Posting a resolution to my own question:
I deleted the folder and recreated the code base, making sure to point my environment to the correct database server. This time it worked. I don't know exactly what had gone missing to cause the original error.