Html to database connection refused

How do I fix the Mysql error “Connection refused”?

The MySQL server error SQLSTATE[HY000] [2002] Connection refused. can be caused by several reasons, if you follow the steps below you should be able to fix this issue:

  • Check that your config file config/config.ini.php (in the Matomo directory) contains the correct and up to date DB credentials under the [database] section. Check that the DB username, DB password, database host, and database port are correct. (if you are unsure, reach out to your database administrator or check in your web hosting account for the up to date credentials).
  • If the config file references host = «localhost» , you can try to change it to 127.0.0.1 instead, for example in your config.ini.php under [database] set host = «127.0.0.1» .
  • If the above changes do not resolve the issue, we recommend you try to connect to MySQL on the command line to check if the credentials are correct and the server works. Connect to the server running Matomo and run this command: mysql -h [hostname] -u [username] -p[password] -D [dbname] (and replace the parameters in [] by the values found in your config.ini.php file.).
  • If the command above works, but you still get the “Connection refused” error in the browser, there may be an issue with PHP. Please reach out to your web hosting company or system administrator.
  • Check that the MySQL Server is running. Connect to the server running the MySQL database and check if the MySQL server is actively running by running this command mysqladmin -u root -p status (which should return an output like this: Uptime: 172505 Threads: 2 Questions: 90 Slow queries: 0 Opens: 157 Flush tables: 3 Open tables: 76 )
  • If you find the DB server is not running, proceed to restart Mysql server (or rebooting the whole server).
  • Or If the Database server have run out of disk space and there is no space left on the server, it may also start to refuse connections.
  • Sometimes MySQL servers are configured to refused some connections (for example connections from outside the network). If your MySQL database is managed by your web hosting company, contact them as they may be able to help.
Читайте также:  Python pandas read excel header

If you still have the SQLSTATE[HY000] [2002] Connection refused. after checking the steps above, feel free to reach out to us by clicking the feedback button below.

Источник

PHP Connection failed: SQLSTATE[HY000] [2002] Connection refused

The error message «SQLSTATE[HY000] [2002] Connection refused» typically indicates that the client was unable to establish a connection to the database server. This can be due to several reasons, such as:

  1. The database server is not running.
  2. The database server is not running on the correct host or port.
  3. There is a firewall blocking access to the database server.
  4. The credentials (username and password) used to connect to the database are incorrect.

To troubleshoot the problem, you should check the following:

  1. Verify that the database server is running.
  2. Check that the database server is running on the correct host and port. You can do this by checking the configuration of your database client (e.g., in a configuration file or your code).
  3. Check for any firewall rules that may be blocking access to the database.
  4. Verify that the credentials used to connect to the database are correct. Ensure the username and password are correct, and the user has the necessary permissions to access the database.

If you still have problems after checking these items, there may be a problem with the database server itself or the network connection between the server and the client. In this case, you may need to contact the system administrator or the database administrator for further assistance.

Источник

Почему php не может подключиться к БД?

FanatPHP

ЗЫ. На боевом сервере ошибки на экран выводить конечно не стоит, а их надо писать в лог (собственно, именно поэтому все эти die — это ужас). И на боевом сервере display_errors надо отключать, а log_errors наоборот — подключать.
Если совсем не можешь найти, где у сервера висит лог ошибок, можешь задать свой собственный, с помощью функции ini_set(‘error_log’,’/путь/к/файлу’); . Но только размещать его надо разумеется в папке недоступной пользователям сайта

Если же говорить о конкретно этой проблеме, то это очень забавная ошибка, в которой смешалась куча старого карго культ кода, который и сам по себе использовать не стоит, и вдобавок он здесь написан неправильно.

Если разобраться, то код or die(«Ошибка1 » . mysqli_error($link)); очень смешной (это не к тебе претензия, никто не ожидает от тебя понимания таких тонкостей, которые не то что новички, а половина здешних «кураторов» не понимают).
Что тут происходит?
слово or die (которое на самом деле вообще нельзя никогда писать) пишут тогда, когда ожидают что в переменной $link будет значение false. Но если в $link будет false, то тогда её бессмысленно подставлять в mysqli_error. Именно поэтому для получения ошибки соединения в мускули есть отдельная специальная функция.

Но как я говорил выше, применять её не следует, как и or die.

Источник

Как решить проблему при подключении к бд Connection refused?

Добрый день, пытаюсь подключится к бд, но получаю вот такую ошибку в строке подключения «Connection failed: Connection refused».
В чем проблема, в каком направлении копать?

Через HeidiSQL подключаюсь без проблем, гуглить пробовал, перелопатил кучу страниц и советов, но ничего что решило бы проблему не встретил

У меня указанно в переменной $host ip и порт

Вот такого плана:
$host=»11.22.33.44:5600″

maks78945, в какой переменной?
В конфиге MySQL указан хост:порт, который он слушает. Вот на этот хост:порт и надо конектиться.

Папа Стифлера, вот пример кода в php
7a0cc53b4f.png
в результате получаю ошибку, но при подключении через heidiSQL всё подключается
fa31e8d7c0.png

Подскажите пожалуйста, что я не правильно указал, я уже перепробовал все вариации которые только получилось найти в интернете

Чудес не бывает. Если не подключается — значит где-то вы ошиблись.
IP-адрес точно один и тот же?
PHP-скрипт и HeidiSQL на одной машине или на разных?
Что прописано в конфиге MySQL?

Папа Стифлера,
доступы скопированы, ошибок нет
на разных, HeidiSQL на рабочий машине, а скрипт на сервере, но доступ открыт для всех

Нет доступов к конфигам, мне доступ предоставил администратор

Источник

Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /var/www/html/wordpress/wp-includes/wp-db.php on line 1626

I’m just starting to code and I try to host a WordPress website on a server of my school. However, as soon as I upload the website on the WordPress interface with the plugin «all-in-one migration», the database crashed. WordPress gives me the error :

Warning: mysqli_real_connect(): (HY000/2002): Connection refused in /var/www/html/wordpress/wp-includes/wp-db.php on line 1626 
● mariadb.service - MariaDB 10.3.22 database server Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled) Active: deactivating (final-sigterm) (Result: timeout) since Thu 2020-06-18 21:23:34 UTC; 28min ago Docs: man:mysqld(8) https://mariadb.com/kb/en/library/systemd/ Process: 10644 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS) Process: 10645 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS) Process: 10647 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 Main PID: 10695 (mysqld) Status: "Waiting for page cleaner" Tasks: 3 (limit: 563) Memory: 65.1M CGroup: /system.slice/mariadb.service └─10695 /usr/sbin/mysqld Jun 18 21:23:40 genius systemd[1]: Starting MariaDB 10.3.22 database server. Jun 18 21:23:41 genius mysqld[10695]: 2020-06-18 21:23:41 0 [Note] /usr/sbin/mysqld (mysqld 10.3.22-MariaDB-0+deb10u1) starting as process 10695 . Jun 18 21:39:50 genius systemd[1]: mariadb.service: State 'stop-sigterm' timed out. Skipping SIGKILL. 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111) 

I tried to restart the database, but it doesn’t return any response. By searching on StackOverflow, a few answers suggest changing localhost to a local IP like 127.0.0.1 in the file «wp-config.php», but it didn’t change anything. Can you help me please ?

Источник

Оцените статью