SQLSTATE[HY000] [2002] Connection refused – Laravel 5

Posted on

laravel-slant

I’ve started to move forward with Web development but first I needed to study some kind of framework. I picked Laravel 5 with PHP and MySQL (for no particular reason whatsoever).

Anyway I followed the instructions and then entering the command php artisan migrate I ran into this error:

  [PDOException]
  SQLSTATE[HY000] [2002] Connection refused

great .. Well this tells me my SQL configurations haven’t been set up. Which is bang on the spot because I don’t have any database setup. So setting up is pretty easy:

Use this guide ( http://coolestguidesontheplanet.com/get-apache-mysql-php-and-phpmyadmin-working-on-osx-10-11-el-capitan/#mysql )

Installation all done. Moving along ..

  [PDOException]
  SQLSTATE[HY000] [2002] Connection refused

Same error.
Again, MySQL hasn’t been set up … well okay I guess I didn’t link it. So I go back to the page from the URL I just posted, hit this in my terminal:

export PATH="/usr/local/mysql/bin:$PATH"

Now I’ve linked my MySQL path to my Bash profile. Then I go back to my current directory for Laravel ( /Users/benji/Sites/application ) and enter:

➜  application source ~/.bash_profile
➜  application  php artisan migrate
                                                     
  [PDOException]                                     
  SQLSTATE[HY000] [1049] Unknown database 'laravel'  

… Well MySQL is now connecting but I don’t have a database called Laravel ( which I configured in my database.php file ). No problem. Just create it manually.

➜  application  mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 646
Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE laravel;
Query OK, 1 row affected (0.00 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| laravel            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

mysql> use laravel
Database changed
mysql> show tables;
Empty set (0.00 sec)

Should be good now. Try migrate again:

➜  application  php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrated: 2016_02_06_074417_create_tasks_table
➜  application  mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 665
Server version: 5.7.9 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| laravel            |
| mysql              |
| performance_schema |
| sys                |
+--------------------+

mysql> use laravel;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+-------------------+
| Tables_in_laravel |
+-------------------+
| migrations        |
| password_resets   |
| tasks             |
| users             |
+-------------------+
4 rows in set (0.00 sec)

And now we’re done. Excellent! moving along.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s