Cannot run Laravel migration on Homestead - php

I have been trying to run migration since yesterday but database connection is preventing it
Note: I can access the database very well from other projects. This only happens with laravel on homestead. Here is the output of the php artisan migrate command:
SQLSTATE[HY000] [1045] Access denied for user
'abdellah'#'192.168.10.10' (using password: YES) (SQL: select * from
information_schema.tables where table_schema = furbook and table_name
= migrations and table_type = 'BASE TABLE')
This is my .env database config
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=furbook
DB_USERNAME=abdellah
DB_PASSWORD=bonjour1
And this is the database.php file
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'furbook'),
'username' => env('DB_USERNAME', 'abdellah'),
'password' => env('DB_PASSWORD', 'bonjour1'),
'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 am running on Homestead environment.
Thanks.

Have you made sure everything is spelled correctly?
The only other thing I can think of is adding an extra 0 at the end of the port (DB_PORT=33060).
It's weird but I had a fresh Laravel project using homestead and the only way I could access the DB artisan commands in the terminal was to add a 0 on the port but then I had to take it off again once accessing it through HTTP.

I was able to run the migration successfully by setting the DB username to homestead and DB password to secret.
DB_USERNAME=homestead
DB_PASSWORD=secret

Related

Artisan migrate error: Illuminate\Database\QueryException

I am trying to migrate and already installed Xampp and also already uncomment the ";extension=php_pdo_mysql.dll" and ";extension=pdo_mysql" in the php.ini file, and still getting that error:
Illuminate\Database\QueryException
could not find driver (SQL: select * from information_schema.tables where table_schema = rav2 and table_name = migrations and table_type = 'BASE TABLE')
PDOException::("could not find driver")
Any ideas?
Thank you!
Maybe, you don't set correct db states at .env.
Check your .env params that you want to connect your database.
for example, table_type = 'BASE TABLE' seems to be wrong?
first, check your php.ini is correct like
# Windows
extension=php_pdo_mysql.dll
# Linux
extension=php_pdo_mysql.so
Is that uncommented ?
if you have ;,remove that.
and you need to restart your xampp after fixing that php.ini.
do /etc/init.d/httpd restart
also your laravel env may be wrong ... so fix .env like:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE= your database name
DB_USERNAME= your database user name
DB_PASSWORD= your database password
and you should check your database config like:
/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', 'your database name'),
'username' => env('DB_USERNAME', 'your database user name'),
'password' => env('DB_PASSWORD', 'your database 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'),
]) : [],
],

Access denied for user 'root'#'pop-os' when running migrations on external host

I'm trying to run laravel migration on another mariadb in the same network (for localhost it works fine). I'm able to access this database using mysql -u root -p 192.168.2.100 just fine.
However using php artisan migrate I get an error
Error message:
SQLSTATE[HY000] [1045] Access denied for user 'root'#'pop-os' (using
password: YES) (SQL: select * from information_schema.tables where
table_schema = 92.168.2.166 and table_name = migrations and table_type
= 'BASE TABLE')
I am running this from pop-os (linux) , but I do not understand why it's using this as a host? I do not have 'pop-os' in my configuration anywhere.
Configuration
ENV File:
DB_CONNECTION=mysql
DB_HOST=192.168.2.100
DB_PORT=3306
DB_DATABASE=Laravel_db
DB_USERNAME=root
DB_PASSWORD=***
database.php (mysql)
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'Laravel_db'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', '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'),
]) : [],
],
laravel version 9.29.0
Are you sure there is an database user named 'root' with password you are using?
Try to log directly into that database (for example from console) and see if that works.
Also try to give permissions to user 'root':
GRANT ALL PRIVILEGES ON *.* TO 'root'#'ip_address' IDENTIFIED BY 'PASSWORD' WITH GRANT OPTION;

Laravel Mysql setup on ubuntu giving error [1698] on running php aritsan migrate

I installed laravel and setup username and database in mysql.
Then I entered the credentials in database.php file in Laravel project.
'mysql' => [
'driver' => 'mysql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'msn_test1'),
'username' => env('DB_USERNAME', 'msn_user' ),
'password' => env('DB_PASSWORD', 'Passw0rd!'),
'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'),
]) : [],
],
But when I run:
php artisan migrate
I get this error:
SQLSTATE[HY000] [1698] Access denied for user 'root'#'localhost' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
I am new to Laravel. Could someone help me with the setup.
The second parameter is the fallback value env('the_env_property_name', 'fallback_variable'), it will fallback if it is not present in the .env file.
You should put these variables in the .env file, create your .env file by copying the .env.example to .env. Set the variables as done below, they are probably already there.
DB_CONNECTION=mysql
DB_USERNAME=msn_user
DB_PASSWORD=Passw0rd!
The .env file is hidden in the project home folder. I found while creating a new one.

Unable to change laravel database

So first thing first i've created migration tables and it successfully migrated and seeded. i've change the .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=jj
DB_USERNAME=root
DB_PASSWORD=
i've tried to change the 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', 'jj'),
'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'),
]) : [],
],
but i'm still unable to login. the error says SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from `users` where `username` = admin limit 1) even though i've migrated and seeded the database
If the configuration looks okay and you are 100% certain that MySQL is running, you might want to clear the configs and caches.
php artisan config:clear
php artisan cache:clear
Try the config one and then the cache if the problem isn't resolved by the first command.
You can read more about the commands here

Laravel SQL Connection - Artisan Migrate Works, but Application Can't Connect

I'm an irregular Laravel user, and am trying to connect to a remote SQL database.
I've gotten the artisan commands working to create migrations and from the command line I can successfully connect to the database. But, when I try to load the application, the connection fails.
Could not connect to the database. Please check your configuration. error:PDOException: SQLSTATE[HY000] [1045] Access denied for user 'myuser'#'222.222.222.222' (using password: YES) in ... {file location}
What are artisan and the actual app framework doing differently that this connection would respond differently between the 2?
Here is the mysql connection in the database.php file:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '123.123.123.123'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'mydb'),
'username' => env('DB_USERNAME', 'myuser'),
'password' => env('DB_PASSWORD', 'mypass'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '','strict' => true,
'engine' => null,
'sslmode' => 'require',
'options' => array(
PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false,
PDO::MYSQL_ATTR_SSL_KEY => 'certs/client-key.pem',
PDO::MYSQL_ATTR_SSL_CERT => 'certs/client-cert.pem',
PDO::MYSQL_ATTR_SSL_CA => 'certs/server-ca.pem',
),
And this is the local environment file:
DB_CONNECTION=mysql
DB_HOST=123.123.123.123
DB_PORT=3306
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mypass
I am running the application locally, but the MySQl server is remote.
It turns out that the root cause was that PDO doesn't like the cert generated by Google Cloud SQL.

Categories