[PrestaShopException] Link to database cannot be established: SQLSTATE[HY000] [2002] Connection refused

Keywords: PrestaShop - Google Cloud Platform - Technical issue - Other
bnsupport ID: d3186d92-81d7-528a-f910-d958e218e27f
Description:
Recently I runout of space, and after expanded de disk I can’t connect to de database. Try couple of thing without result.
Here are some errors log that I found.

sudo /opt/bitnami/ctlscript.sh restart

Job for bitnami.service failed because the control process exited with error code.
See "systemctl status bitnami.service" and "journalctl -xe" for details.

systemctl status bitnami.service

● bitnami.service - LSB: bitnami init script
   Loaded: loaded (/etc/init.d/bitnami; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2021-05-04 18:27:36 UTC; 14min ago
  Process: 2079 ExecStart=/etc/init.d/bitnami start (code=exited, status=1/FAILURE)
    Tasks: 1177 (limit: 4415)
   Memory: 329.2M
   CGroup: /system.slice/bitnami.service
           ├─ 705 php-fpm: master process (/opt/bitnami/php/etc/php-fpm.conf)
           ├─ 710 php-fpm: pool www
           ├─ 711 php-fpm: pool www
           ├─ 712 php-fpm: pool www
           ├─ 713 php-fpm: pool www
           ├─ 714 php-fpm: pool www
           ├─ 715 php-fpm: pool www
           ├─ 716 php-fpm: pool www
           ├─ 718 php-fpm: pool www
           ├─ 719 php-fpm: pool www
           ├─ 720 php-fpm: pool www
           ├─ 721 php-fpm: pool www
           ├─ 722 php-fpm: pool www
           ├─ 724 php-fpm: pool www
           ├─ 725 php-fpm: pool www
           ├─ 726 php-fpm: pool www
           ├─ 727 php-fpm: pool www
           ├─ 728 php-fpm: pool www
           ├─ 729 php-fpm: pool www
           ├─ 730 php-fpm: pool www
           ├─ 731 php-fpm: pool www
           ├─ 732 php-fpm: pool www
           ├─ 733 php-fpm: pool www
           ├─ 734 php-fpm: pool www
           ├─ 735 php-fpm: pool www
           ├─ 737 php-fpm: pool www
           ├─ 738 php-fpm: pool www
           ├─ 739 php-fpm: pool www
           ├─ 740 php-fpm: pool www
           ├─ 742 php-fpm: pool www
           ├─ 743 php-fpm: pool www
           ├─ 744 php-fpm: pool www
           ├─ 745 php-fpm: pool www
           ├─ 746 php-fpm: pool www
           ├─ 747 php-fpm: pool www
           ├─ 748 php-fpm: pool www
           ├─ 749 php-fpm: pool www
           ├─ 750 php-fpm: pool www
           ├─ 751 php-fpm: pool www
           ├─ 752 php-fpm: pool www
           ├─ 753 php-fpm: pool www
           ├─ 794 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─ 797 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─ 798 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─ 799 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─ 800 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─1449 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─1612 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           ├─1613 /opt/bitnami/apache/bin/httpd -f /opt/bitnami/apache/conf/httpd.conf
           └─2044 php-fpm: pool www

May 04 18:27:36 prestashop-1-vm bitnami[2079]: mariadb 18:27:36.43 ERROR ==> mariadb did not start
May 04 18:27:36 prestashop-1-vm bitnami[2079]: 2021-05-04T18:27:36.433Z - error: Unable to perform start operation Export start for mariadb failed with exit
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/010_bitnami_agent_extra...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/020_bitnami_agent...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/030_update_welcome_file...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/040_bitnami_credentials_file.
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/050_clean_metadata...
May 04 18:27:36 prestashop-1-vm systemd[1]: bitnami.service: Control process exited, code=exited, status=1/FAILURE
May 04 18:27:36 prestashop-1-vm systemd[1]: bitnami.service: Failed with result 'exit-code'.
May 04 18:27:36 prestashop-1-vm systemd[1]: Failed to start LSB: bitnami init script.

journalctl -xe

--
-- The job identifier is 590.
May 04 18:26:33 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/010_resize_fs...
May 04 18:26:34 prestashop-1-vm bitnami[2079]: resize2fs 1.44.5 (15-Dec-2018)
May 04 18:26:34 prestashop-1-vm bitnami[2079]: The filesystem is already 10452736 (4k) blocks long.  Nothing to do!
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/020_hostname...
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/030_swap_file...
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/040_check_if_demo_machine...
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/050_change_boot_log_permission
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Running /opt/bitnami/var/init/pre-start/060_get_default_passwords...
May 04 18:26:34 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:26:33+00:00 ## INFO ## Starting services...
May 04 18:26:35 prestashop-1-vm bitnami[2079]: 2021-05-04T18:26:35.102Z - info: Saving configuration info to disk
May 04 18:26:35 prestashop-1-vm bitnami[2079]: 2021-05-04T18:26:35.527Z - info: Performing service start operation for php
May 04 18:26:35 prestashop-1-vm bitnami[2079]: php 18:26:35.84 INFO  ==> php-fpm is already running
May 04 18:26:35 prestashop-1-vm bitnami[2079]: 2021-05-04T18:26:35.848Z - info: Performing service start operation for apache
May 04 18:26:36 prestashop-1-vm bitnami[2079]: apache 18:26:36.12 INFO  ==> apache is already running
May 04 18:26:36 prestashop-1-vm bitnami[2079]: 2021-05-04T18:26:36.128Z - info: Skipping service start operation for varnish
May 04 18:26:36 prestashop-1-vm bitnami[2079]: 2021-05-04T18:26:36.128Z - info: Performing service start operation for mariadb
May 04 18:27:36 prestashop-1-vm bitnami[2079]: mariadb 18:27:36.43 ERROR ==> mariadb did not start
May 04 18:27:36 prestashop-1-vm bitnami[2079]: 2021-05-04T18:27:36.433Z - error: Unable to perform start operation Export start for mariadb failed with exit
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/010_bitnami_agent_extra...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/020_bitnami_agent...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/030_update_welcome_file...
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/040_bitnami_credentials_file.
May 04 18:27:36 prestashop-1-vm bitnami[2079]: ## 2021-05-04 18:27:36+00:00 ## INFO ## Running /opt/bitnami/var/init/post-start/050_clean_metadata...
May 04 18:27:36 prestashop-1-vm systemd[1]: bitnami.service: Control process exited, code=exited, status=1/FAILURE
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- An ExecStart= process belonging to unit bitnami.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 1.
May 04 18:27:36 prestashop-1-vm systemd[1]: bitnami.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- The unit bitnami.service has entered the 'failed' state with result 'exit-code'.
May 04 18:27:36 prestashop-1-vm systemd[1]: Failed to start LSB: bitnami init script.
-- Subject: A start job for unit bitnami.service has failed
-- Defined-By: systemd
-- Support: https://www.debian.org/support
--
-- A start job for unit bitnami.service has finished with a failure.
--
-- The job identifier is 590 and the job result is failed.
May 04 18:27:36 prestashop-1-vm sudo[2070]: pam_unix(sudo:session): session closed for user root
May 04 18:29:50 prestashop-1-vm dhclient[342]: DHCPREQUEST for 10.142.0.6 on ens4 to 169.254.169.254 port 67
May 04 18:29:50 prestashop-1-vm dhclient[342]: DHCPACK of 10.142.0.6 from 169.254.169.254
May 04 18:29:50 prestashop-1-vm dhclient[342]: bound to 10.142.0.6 -- renewal in 1715 seconds.
May 04 18:32:24 prestashop-1-vm sshd[2314]: Received disconnect from 45.146.165.72 port 57900:11: Client disconnecting normally [preauth]
May 04 18:32:24 prestashop-1-vm sshd[2314]: Disconnected from authenticating user root 45.146.165.72 port 57900 [preauth]
May 04 18:34:41 prestashop-1-vm sshd[2316]: Received disconnect from 103.114.221.16 port 40764:11: Bye Bye [preauth]
May 04 18:34:41 prestashop-1-vm sshd[2316]: Disconnected from authenticating user root 103.114.221.16 port 40764 [preauth]
May 04 18:40:05 prestashop-1-vm sshd[2319]: Received disconnect from 81.69.253.29 port 56100:11: Bye Bye [preauth]
May 04 18:40:05 prestashop-1-vm sshd[2319]: Disconnected from authenticating user root 81.69.253.29 port 56100 [preauth]
May 04 18:44:07 prestashop-1-vm sshd[2323]: Did not receive identification string from 205.185.120.245 port 59598
May 04 18:53:18 prestashop-1-vm sshd[2324]: Received disconnect from 209.141.37.126 port 48654:11: Bye Bye [preauth]
May 04 18:53:18 prestashop-1-vm sshd[2324]: Disconnected from 209.141.37.126 port 48654 [preauth]

Hello @carlosmuerto,

Could you please try running the following commands and share their output:

sudo /opt/bitnami/gonit/bin/gonit --verbose status
sudo /opt/bitnami/gonit/bin/gonit --verbose start 
sudo /opt/bitnami/ctlscript.sh status
sudo /opt/bitnami/ctlscript.sh restart
sudo tail -n 45 /opt/bitnami/mariadb/logs/mysqld.log

Regards,
Francisco de Paz

$ sudo /opt/bitnami/gonit/bin/gonit --verbose status


Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

$ sudo /opt/bitnami/gonit/bin/gonit --verbose start


Failed to start mariadb

$ sudo /opt/bitnami/ctlscript.sh status


Cannot find any running daemon to contact. If it is running, make sure you are pointing to the right pid file (/var/run/gonit.pid)

$ sudo /opt/bitnami/ctlscript.sh restart


Restarting services..

Job for bitnami.service failed because the control process exited with error code.

See "systemctl status bitnami.service" and "journalctl -xe" for details.

$ sudo tail -n 45 /opt/bitnami/mysql/data/mysqld.log


tail: cannot open '/opt/bitnami/mysql/data/mysqld.log' for reading: No such file or directory

Hello @carlosmuerto,

My bad, there was a typo in the last command to run; it should have been mariadb instead of mysql. Edited now.

Could you also check the following thread and follow the instructions of my colleagues:

Regards,
Francisco de Paz

2021-05-04 18:26:36 140308883259200 [Note] InnoDB: Highest supported file format is Barracuda.
2021-05-04 18:26:36 140308883259200 [Note] InnoDB: 128 rollback segment(s) are active.
2021-05-04 18:26:36 140308883259200 [Note] InnoDB: Waiting for purge to start
2021-05-04 18:26:36 140308883259200 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.49-89.0 started; log sequence number 97650596
2021-05-04 18:26:36 140308883259200 [Note] Plugin 'FEEDBACK' is disabled.
2021-05-04 18:26:36 140308883259200 [Note] Recovering after a crash using tc.log
2021-05-04 18:26:36 140308883259200 [ERROR] Can't init tc log
2021-05-04 18:26:36 140308883259200 [ERROR] Aborting
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: The InnoDB memory heap is disabled
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Using Linux native AIO
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Using SSE crc32 instructions
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Initializing buffer pool, size = 256.0M
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Completed initialization of buffer pool
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Highest supported file format is Barracuda.
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: 128 rollback segment(s) are active.
2021-05-05 20:53:54 140208555933504 [Note] InnoDB: Waiting for purge to start
2021-05-05 20:53:54 140208555933504 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.49-89.0 started; log sequence number 97650606
2021-05-05 20:53:54 140208555933504 [Note] Plugin 'FEEDBACK' is disabled.
2021-05-05 20:53:54 140208555933504 [Note] Recovering after a crash using tc.log
2021-05-05 20:53:54 140208555933504 [ERROR] Can't init tc log
2021-05-05 20:53:54 140208555933504 [ERROR] Aborting
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: The InnoDB memory heap is disabled
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Using Linux native AIO
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Using SSE crc32 instructions
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Initializing buffer pool, size = 256.0M
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Completed initialization of buffer pool
2021-05-05 20:55:50 140700593545024 [Note] InnoDB: Highest supported file format is Barracuda.
2021-05-05 20:55:51 140700593545024 [Note] InnoDB: 128 rollback segment(s) are active.
2021-05-05 20:55:51 140700593545024 [Note] InnoDB: Waiting for purge to start
2021-05-05 20:55:51 140700593545024 [Note] InnoDB:  Percona XtraDB (http://www.percona.com) 5.6.49-89.0 started; log sequence number 97650616
2021-05-05 20:55:51 140700593545024 [Note] Plugin 'FEEDBACK' is disabled.
2021-05-05 20:55:51 140700593545024 [Note] Recovering after a crash using tc.log
2021-05-05 20:55:51 140700593545024 [ERROR] Can't init tc log
2021-05-05 20:55:51 140700593545024 [ERROR] Aborting

Hello @carlosmuerto,

It seems your database may be corrupted. Please try following our Recover A MySQL/MariaDB Database and check whether there are some tables that need to be recovered.

Regards,
Francisco de Paz

$sudo mysqld --skip-grant-tables --user=mysql --skip-external-locking --port=3306 --sock=/opt/bitnami/mysql/tmp/mysql.sock

2021-05-10 16:40:32 140372341907264 [Note] Using unique option prefix 'sock' is error-prone and can break in the future. Please use the full name 'socket' instead.
2021-05-10 16:40:32 140372341907264 [Note] mysqld (mysqld 10.1.46-MariaDB) starting as process 2551 ...

sudo mysql -u root -p

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/bitnami/mariadb/tmp/mysql.sock' (2 "No such file or directory")

then can’t continue the guide