Trying to connect Laravel to Mysql via XAMPP - mysql

I'm trying to get my laravel app and the mysql database in XAMPP connected and struggling. On http://localhost:8080/aws-upload/public/ I get the following error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mydb2.files' doesn't exist (SQL: select * from `files`)
It then prompts me to migrate, if I migrate on the chrome button provided by laravel the site appears and starts to work, however if I try to migrate through the terminal I get:
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = mydb2 and table_name = migrations and table_type = 'BASE TABLE')
I've created the database in phpMyAdmin called mydb2 and updated my .env file to:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mydb2
DB_USERNAME=root
DB_PASSWORD=
This is my database.php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydb2'),
'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,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
Thanks

In your database.php file:
'host' => env('DB_HOST', 'localhost'), try changing localhost to 127.0.0.1
In your .env file:
At the top of the file, you'll see it says APP_URL=http://example.com - change the url to APP_URL=http://127.0.0.1

Related

Laravel is unable to identify the data in phpmyadmin

I use Laravel
When I try to access Localhost:8000 I get an error
Illuminate\Database\QueryException
SQLSTATE[HY000] [1049] Unknown database 'my_data' (SQL: select `title`,`id` from `table_8` where `id` = 24)
I have a database called my_data in phpmyadmin
XAMPP\volumes\root\htdocs\project\.env
_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= my_data
DB_USERNAME=root
DB_PASSWORD=
XAMPP\volumes\root\htdocs\project\config\database.php
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'my_data'),
'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,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
I changed the DB_DATABASE to my_data in the .env file
And I ran the command
$php artisan cheat:clear
And yet the error is still the same error
Illuminate\Database\QueryException
SQLSTATE[HY000] [1049] Unknown database 'my_data' (SQL: select `title`,`id` from `table_8` where `id` = 24)
I am use Mac
i think your username and password of phpmyadmin is wrong. please check it out. of different. fix it. and try again

Trying to connect laravel to mysql but i keep getting an error

I have my laravel app running and i'm trying to connect it to a Mysql database. I'm using XAAMP for this. After getting Apache and Mysql is running (Mysql is running on port 3308). I reconfigured my .env file and database.php file and I've run php artisan config cache. However when i try to create a database from my terminal using create database xxx, xxx database is created but when i check phpmyadmin on my browser, i can't find the xxx datatbase.
Here's my database.php file:
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3308'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'test123'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
And here's my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3308
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=test123
Solved it but i had to clear up port 3306 so that XAAMP mysql could use it. Cleared it by ending all mysql tasks under task manager.

Laravel 7 SQLSTATE[HY000] [2002] No such file or directory

I had a laravel 7 app I developed on my local (MAMP). I now want to set it up on my website hosting account (apache2, php7.4, mysql server). I did a git pull to pull down all the files and now when I do a
php artisan migrate
I get an error that says
SQLSTATE[HY000] [2002] No such file or directory (SQL: create table `migrations` (`id` int unsigned not null auto_increment primary key, `migration` varchar(191) not null, `batch` int not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')
I am able to login to the phpmyadmin on the hosting server and see my empty database there.
My env file looks like this:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=commandcenterdb
DB_USERNAME=****
DB_PASSWORD=******
and my config/database.php file looks like this
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE',' commandcenterdb'),
'username' => env('DB_USERNAME', '*****'),
'password' => env('DB_PASSWORD', '********'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => false,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
I got the same error when using MAMP on a mac
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = php-laravel and table_name = migrations)
I solved it by adding DB_SOCKET on .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your-database-name
DB_USERNAME=your-username
DB_PASSWORD=your-password
DB_SOCKET=/Applications/MAMP/tmp/mysql/mysql.sock
if it doesn't work try to modify the charset and collation on config/database.php file
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]
its also worth to cross check ,i had UNIX_SOCKET instead of DB_SOCKET in the .env

Laravel 6 multiple database authentication problem

I have two DB connection as bellow:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sales_report
DB_USERNAME=root
DB_PASSWORD=
DB_CONNECTION=sqlsrv
DB_HOST=192.168.102.11
DB_PORT=1433
DB_DATABASE=Some_Name
DB_USERNAME=XXXXXX
DB_PASSWORD=XXXXXX
I am authenticating with mysql also written code as bellow:
class User extends Authenticatable
{
use Notifiable;
protected $connection = 'mysql';
All DB connections are ok but still it takes too long time to login. It also does not show any result. Could you please help?
Because your env db configuration key_name is the same,
It seems laravel choose the second connection, so it cannot find the connection mysql. The first connection is covered by second.
Change another connection key name for .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sales_report
DB_USERNAME=root
DB_PASSWORD=
DB_SRV_CONNECTION=sqlsrv
DB_SRV_HOST=Host_name
DB_SRV_PORT=1433
DB_SRV_DATABASE=DB_name
DB_SRV_USERNAME=user
DB_SRV_PASSWORD=password
In your config/database.php
'default' => env('DB_CONNECTION', 'mysql'),
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
...
],
'sql_srv' => [
'driver' => 'sqlsrv',
'host' => env('DB_SRV_HOST', '127.0.0.1'),
'port' => env('DB_SRV_PORT', '3306'),
You can check the connection configuration in your tinker:
config('database.connections.mysql')
If it still not work, you can clear the config cache:
php artisan config:clear
php artisan optimize
Change your .env file to:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=sales_report
DB_USERNAME=root
DB_PASSWORD=
DB2_HOST=Host_name
DB2_PORT=1433
DB2_DATABASE=DB_name
DB2_USERNAME=user
DB2_PASSWORD=password
Then in your config/database.php change the SQL server configuration to use the new names:
...
'connections' => [
// ...
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
// ...
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB2_HOST', 'localhost'),
'port' => env('DB2_PORT', '1433'),
'database' => env('DB2_DATABASE', 'forge'),
'username' => env('DB2_USERNAME', 'forge'),
'password' => env('DB2_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
],
],
...
Doing this will set the default database to mysql but you can use the alternative connection in each model or on the query builder:
class User extends Authenticatable
{
use Notifiable;
protected $connection = 'sqlsrv';
or
DB::connection('sqlsrv')->table('users')->...
You can change the default by changing the DB_CONNECTION entry in your .env file but then you need to override the connection to mysql where needed.

Laravel 5.4 : SQLSTATE[HY000] [2002] No such file or directory

I know there is a lot of topics on this error but it seems that I already try almost everything and it doesn't work at all.
So I've set up my .env file like this:
APP_NAME=Neuralia
APP_ENV=local
APP_KEY=(key)
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://127.0.0.1:8000
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=neuralia
DB_USERNAME=username
DB_PASSWORD=password
and my config/database.php like this:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'neuralia'),
'username' => env('DB_USERNAME', 'username'),
'password' => env('DB_PASSWORD', 'password'),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
I tried with host => localhost, I cleared my config / cache and dump-autoload but I still get the error when I try to create a user from the register form.
I can use php artisan migrate:refresh etc but not the register / login stuff :/
do you have any ideas please?
Thanks