{"id":9797,"date":"2020-01-31T05:35:22","date_gmt":"2020-01-31T05:35:22","guid":{"rendered":"https:\/\/www.devopsschool.com\/blog\/?p=9797"},"modified":"2021-11-13T05:59:35","modified_gmt":"2021-11-13T05:59:35","slug":"laravel-5-5-php-artisan-migrate-error-in-ubuntu-sqlstatehy000-2002-connection-refused","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/laravel-5-5-php-artisan-migrate-error-in-ubuntu-sqlstatehy000-2002-connection-refused\/","title":{"rendered":"Laravel 5.5 php artisan migrate error in Ubuntu: SQLSTATE[HY000] [2002] Connection refused"},"content":{"rendered":"\n<p><strong>How I got this error?<\/strong><br><strong>Ans: <\/strong>I was running <strong><code>php artisan migrate<\/code><\/strong> command in <code>\/opt\/lampp\/htdocs\/project_dir<\/code><\/p>\n\n\n\n<p> <strong>What was the error?<\/strong> <br><code>ubuntu@ip-ip_addr:\/opt\/lampp\/htdocs\/project_dir$ php artisan migrate<br>In Connection.php line 664:<\/code><\/p>\n\n\n\n<p><code>SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = db_name and table_name = migrations<br>   )<\/code><\/p>\n\n\n\n<p><code>In Connector.php line 67:<\/code><\/p>\n\n\n\n<p><code>SQLSTATE[HY000] [2002] Connection refused<\/code><\/p>\n\n\n\n<p><strong>Screenshot of the error:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"154\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73-1024x154.png\" alt=\"\" class=\"wp-image-9799\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73-1024x154.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73-300x45.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73-768x115.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73-1536x231.png 1536w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-73.png 1878w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><strong>Solution:<\/strong><br>1. Open <strong>.env<\/strong> file<br>2. Change the <code>DB_HOST=127.0.0.1<\/code> to <strong>DB_HOST=localhost<\/strong><br>3. Make sure the port number, db name, username and password is correctly mention in the .env before saving it<br>4. Save the .env file then run command: <strong><code>sudo artisan config:cache<\/code><\/strong><br>5. Now, run command: <strong><code>php artisan migrate<\/code><\/strong><\/p>\n\n\n\n<p> <strong>Output after applying the solution:<\/strong> <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"426\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-72-1024x426.png\" alt=\"\" class=\"wp-image-9798\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-72-1024x426.png 1024w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-72-300x125.png 300w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-72-768x319.png 768w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2020\/01\/image-72.png 1051w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Thanks for reading. I hope you enjoyed the article!<\/p>\n\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_16501\"><iframe loading=\"lazy\"  id=\"_ytid_54403\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_16501\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>How I got this error?Ans: I was running php artisan migrate command in \/opt\/lampp\/htdocs\/project_dir What was the error? ubuntu@ip-ip_addr:\/opt\/lampp\/htdocs\/project_dir$ php artisan migrateIn Connection.php line 664: SQLSTATE[HY000] [2002] Connection refused (SQL:&#8230; <\/p>\n","protected":false},"author":12,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[5201],"tags":[],"class_list":["post-9797","post","type-post","status-publish","format-standard","hentry","category-laravel"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=9797"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9797\/revisions"}],"predecessor-version":[{"id":24982,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/9797\/revisions\/24982"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=9797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=9797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=9797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}