SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
found this somewhere and it was helpful
The DB_USERNAME should be set to root if you do not have a default username
If no password is set on the database, clear it DB_PASSWORD
After completion of .env edit must be clear cache: php artisan config:cache
After Run the migrate Artisan command: php artisan migrate
I am getting the following error
[2022-04-07 12:11:23] local.ERROR: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = swimrace and table_name = migrations and table_type = 'BASE TABLE') {"exception":"[object] (Illuminate\\Database\\QueryException(code: 2002): SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = swimrace and table_name = migrations and table_type = 'BASE TABLE') at /var/www/swimrace/vendor/laravel/framework/src/Illuminate/Database/Connection.php:712)
When I run php artisan migrate
I'm running it inside the container using this command docker-compose exec workspace bash
Here my laradock .env configuration:
### MARIADB ###############################################
MARIADB_VERSION=latest
MARIADB_DATABASE=default
MARIADB_USER=root
MARIADB_PASSWORD=root
MARIADB_PORT=3306
MARIADB_ROOT_PASSWORD=root
MARIADB_ENTRYPOINT_INITDB=./mariadb/docker-entrypoint-initdb.d
Here my laravel project .env configuration:
DB_CONNECTION=mysql
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=swimrace
DB_USERNAME=swimrace_user
DB_PASSWORD=raceswim
User and password in this last configuration was created via console into mariadb container and assigned to this account all privileges.
If I try to read database with any database ui tools (PMA, DataGrip, etc) I can see and write inside the database, but not with artisan commands.
Any suggestions?
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
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.
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.