Laravel Migrate Cant connect to MYSQL - php

I have installed a fresh Laravel project (5.7.5) on my Mac (10.13.6).
I have installed mysql (8.0.12) with brew install mysql and the laravel project with the laravel create laraveltest command.
Laravel is running in the Valet environment (2.1.1).
I can connect to the Mysql server with the Sequel Pro client (127.0.0.0, root with no password) and also by the command line mysql -uroot.
I can create a database create database laraveltest and use the database use laraveltest but when I try migrating the database php artisan migrate i get an error:
'PDOException : SQLSTATE[HY000] [2006] MySQL server has gone away')
So it seems that Laravel can't connect to my mysql server.
My .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laraveltest
DB_USERNAME=root
DB_PASSWORD=
I tried uninstalling/installing mysql. restarting the computer. deleting/creating the laravel project. same error.
Any ideas what I can try to resolve this?

input your root password of your php admin i think you do have a password to root php admin right ? DB_PASSWORD="yourpassword"

Related

SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' in laravel 7

Can't able to connect database in only laravel 7
my url is http://localhost:8000/index
Here is my project .env file
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=amazon_services
DB_USERNAME=root
DB_PASSWORD=""
i have run the following commands but still facing error
php artisan config:cache
php artisan config:clear
php artisan cache:clear
But i can able to connect the database in laravel 5.4 version while using url like this http://localhost/larave/laravel5.4/inde but while using laravel 7 with development server not connected
This probably is permission error by mySql.
If you are using root as username with no password please add user privileage to the database table you are connecting to like below.
Furthermore you will also need to grant access to root user to perform specific action on table.
And then
If the above solution did not work for you try following
php artisan config:cache
php artisan config:clear
php artisan cache:clear
Keep your .env file as
DB_USERNAME=root
DB_PASSWORD=
Open .env and change that :
DB_HOST=127.0.0.1
DB_PASSWORD=
If the problem persists, try logging into mysql yourself.

Connecting laravel to postgres db

I am working on a project where I need to connect Laravel to a postgres db. First time doing this, in the past just used mysql. I am getting this error PDOException::("SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host when I try to run php artisan migrate. I am on a mac so I used brew install postgresql. This is a db that already has tables in it.
In my .env file I changed my db to
DB_CONNECTION=pgsql
DB_HOST=<host name>
DB_PORT=5432
DB_DATABASE=<db name>
DB_USERNAME=<user name>
DB_PASSWORD=<password>
What else am I missing?
It seems like your config is missing in pg_hba.conf file.
Suppose you are on localhost, have you tried adding host all all 0.0.0.0/0 md5 entry in your pg_hba.conf? Remember to restart your postgresql services after that.

Laravel 6.x migration failed with Maria DB

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.

php artisan migrate error cause cannot connect to db

I accidentally deleted the database for my project so I am trying to recreate all those tables using php artisan migrate.
I can log into MySQL with mysql -u root -p and then I enter in the password of "password" which will allow me to see all my databases. Since I deleted my database I created another database "endorsify_dev" using Create Database endorsify_dev sql command.
Then, I went to do php artisan migrate, but that gave me an error that I cannot figure out.
My .env file:
The Users in Mysql:
Databases:
Error:
You connected yourself with mysql cli clent as root and with a password. But you PHP error indicated (using password: NO).
I assume your php code (Connection.php and PDOConnection.php) is trying to connect to the mysql database without using DB_PASSWORD provided in your .env file.
This error basically comes from changing .env file values.
SQLSTATE[HY000] [1045] ACCESS denied for user 'root'#'localhost'
(using password: NO)
Your .env file configuration should be something like this:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=endorsify_dev // Your Database Name
DB_USERNAME=root // Your Database Username
DB_PASSWORD= // Your Database Password
NOTE: If no password is set on the database, clear it DB_PASSWORD, empty space must also be removed
If All is correct then After completion of .env edit, You can clear the configuration cache with the following artisan command: php artisan config:cache
Also, check in config/database.php, Check that the old database name has not been used on it.
Also, If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values
To run all of your outstanding migrations, execute the migrate Artisan command:php artisan migrate
Try in your env:
DB_PASSWORD= 'YourPassword'

how to set up a database for laravel 5? (connection refused error)

I am trying to get a laravel5-example project working. One of the steps seems very basic but I do not know how to do it:
Create a database and inform .env
With laravel 5 my .env file looks like:
APP_ENV=local
APP_DEBUG=true
APP_KEY=B0ST6bRoqxVJ2JtUNPtittJup6mRJef2
DB_HOST=127.0.0.1
DB_DATABASE=laravel_base
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
When I try to seed the database I get an error:
$ php artisan migrate --seed
[PDOException]
SQLSTATE[HY000] [2002] Connection refused
How do I create a database so I can run my laravel application on my mac? I have postgres installed. The default for this application is mysql ('default' => 'mysql') in config/database.php. If I change it to 'default' => 'pgsql' I get a different error:
$ php artisan migrate --seed
[PDOException]
could not find driver
I don't really care if I have mysql or psql database, just want it to work. Mysql is the default though, so might be better to stick with that. What are the commands to set up mysql/psql databases for laravel projects?
You should make sure:
You have in your php.ini PDO PostgreSQL enabled (extension=php_pdo_pgsql.dll not starting with ;)
Set in .env DB_CONNECTION to pgsql (or default do pgsql in config/database.php depending what specific version of Laravel you use (5.0 or 5.1/5.2))
If you won't be able to make it work, you should think of installing Laravel Homestead that has everything needed to develop Laravel applications

Categories