My website works, its clearly accessing the database. I can log in and i can create records, etc...
Ive created a new migration, and I'm trying to insert it, but when i run
php artisan migrate
i get the error
[PDOException]
SQLSTATE[HY000] [2002] Connection Refused
My database config has the passwords hidden in the environment so my config looks like this
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOSTNAME'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USERNAME'),
'password' => getenv('DB_PASSWORD'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
my environment variables are loading correctly. What am i missing?
I figured it out. Apparently the environment that artisan was seeing was different from the environment i wanted it to see, so it was using the wrong host
php artisan migrate --env=production
Related
I am using schema builder to create a Mysql table. I am using Ubuntu 14.04.
My connection for Mysql in config/database.php is :
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'firstapp'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
And Code for creating table with schema builder on routes.php
Route::get('/', function () {
Schema::create('art', function($newtable)
{
$newtable->increments('id');
$newtable->string('artists');
$newtable->string('title',500);
$newtable->text('discription');
$newtable->date('created');
$newtable->date('exhibition_date');
$newtable->timestamps();
});
return view('welcome');
});
Thanks
As far a as i know , you must create a migration file using
php artisan migrate:make yourtable
Then yo must go to database folder you will find a new migration file created , then you must open it , and fill it with your schema , once you finish , then run migration
php artisan migrate
And that's all you will see your new table created.
Migrations laravel 5
First i was using xampp mysql and this was also started /etc/init.d/mysql from terminal, Since i am using Ubuntu 14.04.
I solved the problem which i posted above then another problem came up Saying SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES).
I changed the .env file which is placed in the root directory of laravel and i changed the Database Name name and password which i was using for mysql.
It solved that problem too and i am up and running.
I have an unusual problem with my Laravel 4.2 project connecting to MySQL database. This is my database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database_name',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
I use XAMPP for Ubuntu.
First, I've created a database in phpMyAdmin. When I tried to run php artisan migrate, it gave me an error of unknown database 'database_name'. I thought it was silly since I've just created a database in phpMyAdmin. Then I tried creating a database through the command line and tried running the migration again. It worked. Tables were created under the database I specified when I run show tables in the command line. It seems to me that the Laravel project is connected to a different mysql server than the phpMyAdmin. Is that even possible? How can I solve this problem?
I've been trying to solve this for hours but still, no luck. Hope someone can help me with my problem.
I solved the problem by following the solution in the link provided by Bulk. I just have to run sudo /opt/lampp/bin/php artisan migrate instead of the plain php artisan migrate. With this, artisan will use the MySQL version provided by XAMPP.
I'm working on a project (PHP Laravel 4.2) using SVN with team, After I checked out the repository on my disk (local), and tried to open the link localhost/mylaravel, I got this error
PDOException (1045) SQLSTATE[HY000] [1045] Access denied for user
'dbusername'#'xx.xxx.xx.xxx' (using password: YES)
Note: I changed the real username and host IP
the database not locally, It's remotely hosted online. but the project is on localhost.
config/database.php
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
/**
* remote database connection
*/
'mysql' => array(
'driver' => 'mysql',
'host' => 'hostIP:port',
'database' => 'mydatabasename',
'username' => 'mydbusername',
'password' => 'root123456',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'forge',
'username' => 'forge',
'password' => '',
'charset' => 'utf8',
'prefix' => '',
'schema' => 'public',
),
'sqlsrv' => array(
'driver' => 'sqlsrv',
'host' => 'localhost',
'database' => 'database',
'username' => 'root',
'password' => '',
'prefix' => '',
),
)
Just run the following artisan commands in your terminal.
1. php artisan cache:clear
2. php artisan config:cache
Refresh your url now and the login will works perfectly.
$ php artisan cache:clear
Application cache cleared!
$ php artisan config:cache
Configuration cache cleared!
Configuration cached successfully!
Run php artisan cache:clear then php artisan config:cache on your terminal in the respective path.
The above should be the results
I Faced Same Problem i did
php artisan cache:clear
php artisan config:cache
but Same problem found than i run this artisan command
php artisan view:clear
Hope it will helpful.
Note: my project was Laravel 5.*
Just only change .env file and DON'T change config/database.php file. Please make config/database.php file as default.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1 or IP address
DB_PORT=3306
DB_DATABASE='your database name'
DB_USERNAME='your username'
DB_PASSWORD='your password'
it works for me!
Please run the command line:
php artisan optimize
I don't know why when I run a PHPUnit test, I get the following error:
PDOException: SQLSTATE[HY000] [2002] No such file or directory
My testing environment database setting is:
return [
'fetch' => PDO::FETCH_CLASS,
'default' => 'mysql',
'connections' => [
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'clg_test',
'username' => 'root',
'password' => 'veryHardPass',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
]
],
'migrations' => 'migrations',
];
The reason why I am using MySQL as oppose to SQLite is because my migration files use dropColumn which is not supported by SQLite. I call the migration via Artisan::call('migrate') in the setup.
If I actually call migration manually in the terminal via php artisan migrate --env=testing then the migration IS successful and the databases are created.
Why am I then facing the above problem?
Try changing localhost to 127.0.0.1. The message you're getting is indicative of the script not being able to connect to MySQL through a socket, but using an ip should work.
I am trying to set up migrations for the first time and when I run
php artisan migrate:install
from within the root folder of my project I get the following SQLSTATE error:
SQLSTATE[HY000] [2002] No such file or directory
I have tested running mysql to make sure it is working and referenced and I have ran php artisan help:commands to make sure artisan is working (it is).
The website itself is functioning and reading from the database fine.
This may be an issue with the sockets if you're using MAMP or XAMPP.
From http://forums.laravel.io/viewtopic.php?id=980...
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
'database' => 'database',
'username' => 'user',
'password' => 'pass',
'charset' => 'utf8',
'prefix' => '',
),
),
You can pass an optional "unix_socket" to the array and specify the MAMP socket instead of the default location.
Also, try and change 'host' => 'localhost', to 'host'=> '127.0.0.1', because unix does not recognise 'localhost'