I just started downloading laravel 5 today. Where I install my laravel in my desktop. When I try to create a database using laravel comman php artisan migrate:install and it give's me a error SQLSTATE[HY000] [1044] Access denied for user ''#'localhost' to database 'forge' I tried a lot of examples on google but didn't work for me.
I follow on of the steps on the internet where I configure my .env file followed the array contain in database.php database to 'forge', username to 'forge' and password to ''
database.php
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
.env
APP_ENV=local
APP_DEBUG=true
APP_KEY=base64:oqZ6S+IZANLCbszbhef9VSPqd/4rw22oT0mixzsflZo=
APP_URL=http://localhost
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=forge
DB_USERNAME=forge
DB_PASSWORD=''
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
How can I create database just typing php artisan migrate:install and automatically create laravel_migration database in my localhost? Just saw this on the internet. But when I did this it didn't create for me.
As mentioned in the comments, the tutorial assumes you are using their development virtual machine. Since you're not, you need to start up MySQL and do the following:
CREATE DATABASE IF NOT EXISTS forge;
CREATE USER forge#localhost IDENTIFIED BY '';
GRANT ALL PRIVILEGES ON forge.* TO forge#localhost;
Once the database and user are created, you should be good to go. This should be part of their documentation...
Related
I have this project running on Laravel 5.8 and Database on Mysql using XAMPP server.
This is my .env file:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=homestead
DB_PASSWORD=secret
This is my 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' => '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 also created a Database in Xampp named homestead.
this error is showing: SQLSTATE[HY000] [1045] Access denied for user 'user'#'localhost' (using password: YES) (SQL: select * from userswhereemail = test#gmail.com
you need to provide db_name, mysql user_name and password in your .env file.
for xampp default username is 'root' and no password.
so update your .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=homestead
DB_USERNAME=matkagu_satta
DB_PASSWORD=
I've setup Laravel 5.0 (that's a requirement) and set it up to use remote MySQL DB. All migrations and data interactions pass OK, but when trying to use Auth login POST, it fails with PDOException in Connector.php line 47:
SQLSTATE[HY000] [2002] No such file or directory, mentioning " PDO->__construct('mysql:host=localhost;dbname=homestead', 'homestead', 'secret', array('0', '2', '0', false, false))"
WHERE did it take that homestead DSN? Why does it skip the database.php config and .env config? If I try to add to .env some socket info (well it should not count here, right?) the socket path passes to the mentioned PDOException call stack, but hostname, login etc. NOT!
Confused. What am I doing wrong?
UPD
Here's the .env:
APP_ENV=local
APP_DEBUG=true
APP_KEY=SomeRandomString
DB_HOST=mysql.someremteohosting.net
DB_DATABASE=mydb
DB_USERNAME=myuser
DB_PASSWORD=mysuperpassword
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
And here's database.php:
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => storage_path().'/database.sqlite',
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
'sqlsrv' => [
'driver' => 'sqlsrv',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'prefix' => '',
],
],
'migrations' => 'migrations',
],
];
Again, all migrations work. I can create, save and fetch objects in tinker without any problem. The only reference to homestead is in .env.example file.
Not sure what exactly was wrong here. The only place where I found 'homestead' in the app code was in .env.example. I deleted it an ran composer dump-autoload. After that it worked. Still surprised about laravel lurking into .example config without any reason.
I have this in my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=m6twKy7Lr6KKFvVa7QgXUe78xfn08MLn
DB_HOST=localhost
DB_DATABASE=laravel1
DB_USERNAME=root
DB_PASSWORD=somepass
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
And this is in my database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
The database is created and I can see it in phpMyAdmin in browser.
But when I write php artisan migrate I get this error:
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'laravel1'
I have seen the answers on
Laravel Migration - Says unknown database, but it is created , but that didn't helped me.
Try specifying the MySQL port that you are using. Might work out. I had a similar issue like this. Be sure to give the appropriate port where MySQL is installed in ur system(default is 3306).
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'databasename'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
It's been around 5-6 hours since I've been trying to use database in laravel 5.
I've gone through of videos and it confused me a lot.
I have created the model and migration but when i try to migrate it gives me an
[ PDOException ] Driver not found
I've made numerous changes to .env and database.php but nothing works.
I am using laravel 5 with xampp server.
Kindly help
Thank you
.env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=zZfvju3BKjxmLKbl5gsVJ3ymkIvHbGNq
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=medicaldb
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
database.php file
<?php
return [
'fetch' => PDO::FETCH_CLASS,
'default' => env('DB_CONNECTION', 'mysql'),
'connections' => [
'sqlite' => [
'driver' => 'sqlite',
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
],
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'medicaldb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'pgsql' => [
'driver' => 'pgsql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
],
],
'migrations' => 'migrations',
'redis' => [
'cluster' => false,
'default' => [
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
],
],
];
Finally, at last! it worked!!
In php.ini file:
(semi-colon) ; works as a single-line comment in php.ini file.
(semi-colon) was added at the beginning of the line - which disables pdo mysql driver.
I just needed to remove the semi-colon(;) to enable mysql, from the beginning of the line.
Same problem, ubuntu 17.10, Laravel 5.6
It is the issue normally come when you upgrade you php version I get the same issues in my lammp stack while i update from php 7 to 7.1 I get Solve by following command
Open Terminal
sudo apt install php7.1-pdo php7.1-mysql
Have fun with Code
Are you sure you have mysql intalled? also, please check pdo_mysql module is enabled. use phpinfo();
I am new to Laravel5. I tried to create migration table but I get this error
Error Log
This is the database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'larashop'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'melody'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
and this is .env
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=larashop
DB_USERNAME=root
DB_PASSWORD=melody
Please help.
Your screenshot shows "localhost" and your code shows "127.0.0.1". MySQL treats "localhost" and "127.0.0.1" differently.
Make sure you have granted appropriate permissions for 'root'#'localhost' in your database.
http://dev.mysql.com/doc/refman/5.7/en/grant.html