SQLSTATE[HY000] [1049] Unknown database 'ictinder' - php

So for some reason I get this error in my browser when using Laravel. I feel like I got everything set up correctly:
This is my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=ictinder
DB_USERNAME=root
DB_PASSWORD=secret
This is my database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'ictinder'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
This is a screenshots from my phpMyAdmin, it's Dutch so if you don't understand something, let me know
This is what the error looks like in my browser
Thank you for taking your time to help out, or at least read my question!
EDIT 1:
I already tried php artisan cache:clear and php artisan config:clear, both didn't work. I can use php artisan migrate.

If you are using vagrant to run your project. you have to change your db port into 33060 and change your db username into homestead
if you are running your program using php artisan serve, your db port should be 3306 into your db username
see the docs laravel homestead
Hope this can help you

What you need to do in your case is to remove the ictinder from your database and also from your .eve file. then recreate the ictinder again from where it was been remove, it's adventurous to leave the empty DB_PASSWORD like this DB_PASSWORD=, if your MySQL does not have a password, also remember that
If you are using the PHP's default web server (e.g. php artisan serve) you need to restart your server after changing your .env file values.

Related

Error on using different MySQL server in Laravel

Thanks for your attension.
I have a Laravel 5.5 project and I want to use it with a MySQL server - being hosted on another server.
I can access MySQL server on the web browser.
https://xxx.xxx.xxx.xxx/phpmyadmin
And now I want to connect this MySQL server with a Laravel project on my local.
So I changed .env and config/database.php files like this:
.env file
DB_CONNECTION=mysql
DB_HOST=xxx.xxx.xxx.xxx (MySQL server host IP4 address like: 111.111.111.111)
DB_PORT=3306
DB_DATABASE=db_name
DB_USERNAME=user_name
DB_PASSWORD=password
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'xxx.xxx.xxx.xxx'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'db_name'),
'username' => env('DB_USERNAME', 'user_name'),
'password' => env('DB_PASSWORD', 'password'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
After that I tried this:
php artisan config:clear
php artisan cache:clear
php artisan serve
But Laravel project shows me error like this:
"""
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.\r\n
(SQL: select * from `table_name` where `one_filed` = some_value limit 1)
"""
Please help me.
Thanks.
Welcome to stackoverflow. There can be multiple issues, and you may find the correct thing from the docs or phpmyadmin config (if you have access to it):
MySQL configuration my not be on standard port of 3306
It might need SSL configuration to connect to.
The host might not be the same IP address as PHP My Admin as also stated in the comments. Even if the mysql server is accessible via the same host (very unlikely, but possible), the mysql user might have been configured with a special host

Laravel 5.7 SQLSTATE[HY000] [2002] No connection could be made

I am using laravel 5.7 and i am getting this error. But its working fine for older versions. i am using xamp with php 7.3.* . Here is my code
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3308
DB_DATABASE=project
DB_USERNAME=root
DB_PASSWORD=
DB_DEFAULT=mysql
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'project'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'default' => env('DB_DEFAULT', 'mysql')
],
Database is fine and i tried connecting with test.php file, its connecting fine but have problem with laravel 5.7
This error usually means the target machine was reachable, but is not listening on that port.
Some things to check:
The default port for MySQL is 3306, not 3308. Was this change intentional?
XAMPP often requires that you start the database manually. Is it online?
If the database is on your local machine, is it also configured to listen on 3308 instead of 3306 like your Laravel code?
Make sure your config isn't cached: php artisan config:clear
If the database is not on your local machine, then it could easily be a firewall setting causing the problem.
XAMPP to check your PORT number then change DB_PORT. I hope it works
After a lot of research about laravel 5.7 and xamp, i found the solution. It was basically the cache issue in the file bootstrap/cache/config.php .
It was reading this config cache file instead of my new file. I removed it and not its working fine. I am very thankful all of you.

PHP Laravel could not migrate files to database

I'm trying to connect with PHP and MySQL through the database using Laravel doing:
php artisan migrate but I'm experiencing a common error:
"Illuminate\Database\QueryException : could not find driver"
(I'm using XAMPP to start up the server if that makes a difference)
The values I changed in database.php:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'test2'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
],
I also changed the .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3308
DB_DATABASE=test2
DB_USERNAME=root
DB_PASSWORD=
The things I did were:
See if the extension=pdo_mysql is uncommented which it was.
Typed in php artisan migrate:refresh
Restarted Xampp
Deleted and recreated the migration file. Also incremented the last digit of the number (taken advice from one of the answers)
Check the version (which is the latest)
composer update
composer require doctrine/dbal
Check to see if pro_mysql is activated on your install.
You can do this by creating a file and adding the following:
phpinfo();
Then navigate to it in your browser. If it is activated you will see it in the list.
Here is some more info:
http://php.net/manual/en/function.phpinfo.php
Hope that helps.

(2/2) QueryException SQLSTATE[HY000] [1049] Unknown database 'homestead' (SQL: select count(*) as aggregate from `users` where `email` =

I want to try the registration form of laravel where I have to insert my database information in the .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=root
DB_PASSWORD=admin
In my config/database.php file I also change the values to my current database
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'blog'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'admin'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
But, I get the error that my homestead database is unknown. I have know idea where the information comes from ? I don't have connect a database with this name in any file? or should there a third file to change?
#weristsam
You should clear the cache after changing in .env file
run the following commands
php artisan cache:clear
php artisan config:clear
php artisan config:cache
After successfully modifying the .env file and you're still receiving unknown homestead database, don't stress the thing is Laravel is still reading the previous cache and compiled view. Just clear all by using the following command:
php artisan cache:clear
php artisan config:clear
php artisan config:cache
php artisan view:clear

Configuring laravel app for production

everyone. I've recently encountered problems trying to deploy my laravel app to production-like server. So far I've been using it in homestead environment and everything was just fine.
My .env contains something like this:
APP_URL=http://public.server.url
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=myusername
DB_PASSWORD=mypassword
In mysql (running on port 3306) I've set up user 'myusername'#'localhost' with mypassword and indeed I can connect using
mysql -u myusername -p
Even 'php artisan migrate' command works and modifies my database properly.
config/database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'homestead'),
'username' => env('DB_USERNAME', 'myusername'),
'password' => env('DB_PASSWORD', 'mypassword'),
//'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
Problem is my http controllers don't behave correctly. I am getting 500 server error when sending requests on my routes (no matter how dummy logic they do) and 404 not found when trying to reach non-existing route. Also nothing is appended in the log file. So I am guessing as far as registering routes my app works, but right after that it fails. Any suggestions? I would really appreciate any tips.

Categories