Ошибка cannot connect to database

I also struggled with this problem for quite a while.

I came accross this interesting thread from MySQL forum: http://forums.mysql.com/read.php?11,11388,11388#msg-11388

I also came accross (obviously) some good SO Q/A.

It seems that the message mentioned in «user948950» ‘s question can be coming from a wide range of reasons: log file too big, incorrect mysql.ini file values, spaces in the file path, security/acl issue, old entries in the registry, and so on.

So, after trying for 3h to fix this… I abandonned and decided to do a good old re-install.

This is where this post from (again) this MySQL thread came in useful, I quote:

Gary Williams wrote: Hi Guys,

I’ve had exactly the same problem and this is how I got it working
for me, starting with a non working installation.

  1. Stop the windows service for any existing mysql installation.

  2. Uninstall Mysql.

As with most uninstalls, old files are left behind. If your directory
is C:mysql etc then delete the innob, etc, files but leave the
directories themselves as well as any existing databases in ‘data’.
If your directory is C:Program Files etc, delete all the mysql
directories.

  1. It’s now worth running regedit to make sure the old registry entries are deleted as well by the uninstall. If not, delete them.

  2. It’s ok to use the new .msi installer (essential files only), however ….

  3. Do not use their default install path! Some genius set a path with spaces in it! Choose the custom install and select a sensible path,
    ie, C:mysql (note from Adrien: C:mysqldata for … the data)

  4. Do not choose to alter the security settings. Uncheck the relevant box and the install will complete without having to set a root
    password.

I think I have remembered everything.

Good luck

Gary

I did get into troubles when simply copy/pasting the databases I had in my previous «data» directory to the new one. So the work around I found was to export each database (I know… a lot of fun) and then re-import them one by one.

FYI: I used the following command to import C:/<MySQLInstallDir>/My SQL Server x.x/bin/mysql -u root -p <dbName> < "<dirPathOfDump><dumpName>.sql", that is for instance C:/mysql/MySQL Server 5.6/bin/mysql -u root -p mySupaCoolDb < "C:mySupaCoolDbDump20130901.sql"

Are you looking for a solution to “zabbix cannot connect to the database” error ? Here’s how we fix it.

Zabbix is a monitoring software tool. When using zabbix we may encounter many errors like zabbix cannot connect to the database. This may occur due to incorrect database details.

At Bobcares, we often get requests from our customers to fix ‘zabbix cannot connect to the database’ as part of our Server Management Services.

Today, we’ll see the reasons and how our Support Engineers fix this error.

Causes for ‘Zabbix cannot connect to the database’ Error

At Bobcares, where we have more than a decade of expertise in managing servers, we see many customers face problems while managing Zabbix.

Now, let’s see the major reasons for this Zabbix error to occur and we’ll also see how our Support Engineers fix this zabbix database cannot connect error.

Incorrect Database details

Recently one of our customers approached us with the same zabbix problem. He said he was getting an error in his zabbix dashboard like the one shown below in the screenshot.

zabbix cannot connect to database

When we checked in detail, our Support Engineers found that there is mismatch in the details given in database with those in zabbix_server configuration file.

We found that the DBName given in database was not the same as the one given in zabbix configuration file. So, we changed it to the right one. Finally, this fixed the error.

We also Checked and confirmed whether all other values entered were right.

Incorrect DBsocket

We got another request from some other customer. However, the error was similar. Here is the error message our customer was receiving.

[ZXXX] connection to database 'Databasename' failed: [2002] Can't connect to local MySQL server through socket '/var/lib/mysql'

We checked and found that the socket given in mysql configuration file is different from the one specified in the configuration file for zabbix. In mysql configuration DBSocket value was  /var/run/mysql/mysql.sock and in zabbix_server configuration it was  DBSocket=/var/run/mysql. So, we made the following corrections in zabbix configuration file:

XXXX:/usr/share/zabbix # cat /etc/zabbix/zabbix-server.conf
LogFile=/var/log/zabbix/zabbix-server.log
PidFile=/var/run/zabbix/zabbix-server.pid
DBName=*****
DBUser=*****
DBPassword=*************
DBSocket=/var/run/mysql/mysql.sock

And this fixed the problem.

[Need any further assistance in fixing zabbix errors? – We’ll help you]

Conclusion

In short, ‘Zabbix cannot connect to the database’ error may occur due to some reasons like wrong database details or when there is any mismatch in configuration file values, etc. Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = «owonCMyG5nEQ0aD71QM»;

Step 1. Check your network settings

Databases can work locally, on a server, or in the cloud. For server and cloud databases, you need a network connection. To verify that connection is available, use ping and telnet commands.

With the ping command, you can ensure that the destination computer is reachable from the source computer. Open a command line and type the following command: ping -a <host_IP>, where -a is a command option that resolves addresses to hostnames (if it is possible). If you use hostnames with the ping command, a hostname is resolved to the IP address. For example, ping -a example.com resolves to PING example.com (93.184.216.34).

ping -a <host_IP>

Test connection with the ping command

With the telnet command, you can test connectivity to remote computers and issue commands. If you specify a port as a parameter for the telnet command, you can test connectivity to a remote host on the given port. If the connection is successful, you see the message: Connected to <host_IP>.

telnet <host_IP> <port_number>

Test connection with the telnet command

Step 2. Check your connection properties

Each database (MySQL, PostgreSQL, Oracle, or any other vendor) has its own connection settings. Most database include the connection settings:

  • Host: A hostname of a computer or other device that stores a database. It can be an IP address 127.0.0.1 or a domain name localhost.

  • Database: A name of the database to which you want to connect. You can find the database name in the settings of your database server, or you can ask your database administrator. In some cases, it is possible to run a query in a database command line to see names of all available databases. For example, in MySQL you can run SHOW DATABASES;.

    The SHOW DATABASES query

  • User: A name of a user that has sufficient privileges to perform actions with a database. Run a query in a database command line to see names of all available databases. For example, in MySQL you can run SHOW GRANTS;.

    The SHOW GRANTS query

  • Password: A password of the user.

  • Port: A number that identifies a connection point between hosts. Hosts use port numbers to determine to which application, service, or process a connection must be established. Different database vendors use different ports for their databases. The following list is a list of default port numbers.

    Vendor

    Default port

    Amazon Redshift

    5439

    Apache Derby

    1527

    Apache Cassandra

    9042

    Apache Hive

    10000 (Hive Server2) or 9083 (Hive Metastore)

    Azure SQL Database

    1433

    ClickHouse

    8123

    Couchbase Query Query Service

    11210

    Exasol

    8563

    Greenplum

    5432

    H2

    8082

    HSQLDB

    9001

    IBM Db2 LUW

    50000

    MariaDB

    3306

    Microsoft SQL Server

    1433 (TCP), 1434 (UDP might be required)

    MySQL

    3306

    Oracle

    1521

    PostgreSQL

    5432

    Snowflake

    443

    SQLite

    None

    Sybase ASE

    5000

    Vertica

    5433

Verify that the connection settings for the selected database connection are correct. For more information about creating or changing a database connection, see Connecting to database.

Step 3. Check the driver version

With a JDBC driver, you can interact with a database management system (DBMS) from PyCharm. Each DBMS requires its own JDBC driver. Ensure that the driver version and the DBMS version are compatible with each other.

From PyCharm, you can download drivers for all supported vendors. You can check the full list of supported vendors in the Drivers list . Alternatively, you can add your own driver to an existing vendor, or create a new driver entry for the vendor that is not on the Drivers list.

To open the Drivers list, in the Database tool window ( ), click the Data Source Properties icon The Data Source Properties icon or press Shift+Enter.

Download a driver and select the driver version

To download drivers from the JetBrains FTP server, select a vendor from the Drivers list, and click the Download ver. <version_number> link in the Driver files pane.

To change the driver version, click the ver. <version_number> link in the Driver files pane and select the driver version that you need.

The Drivers list and driver settings

    Using user driver files

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. In the Data Sources and Drivers dialog, ensure that you are on the Drivers tab.

    3. In the Data Sources and Drivers dialog, click the Add icon (The Add icon).

    4. In the Name field, type the name of the driver.

    5. In the Driver Files pane, click the Add icon (The Add icon) and select Custom JARs….

    6. Navigate to the JAR file of the JDBC driver, select it, and click OK.

    7. In the Class field, specify the value that you want to use for the driver.

    8. Click Apply.

    9. To create a data source from the driver’s dialog, click Create Data Source.

      Connect to a database with a user driver

    Configure a JDBC driver from the existing connection

    You can add libraries to the existing driver or replace the driver completely.

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon

    Configure a JDBC driver from the existing connection

    You can add libraries to the existing driver or replace the driver completely.

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. In the Data Sources and Drivers dialog, click the Drivers tab, and select a data source where you want to change a driver.

    3. Click the Driver link in data source settings.

    4. Click the provided driver entry, and click Remove (the Remove button).

      To revert changes, click the Roll back Changes icon (the Roll back Changes icon) that is in the lower-right part of the window.

    5. In the Driver files pane, click the Add icon (The Add icon) and select Custom JARs….

    6. In the file browser, navigate to the JAR file of the JDBC driver, select it, and click OK.

    7. In the Class field, specify the value that you want to use for the driver .

    8. Click Apply.

      Add a user driver to an existing connection

    Step 4. Check if the connection with SSH or SSL is required

    To make a connection to a database more secure, some services require SSH or SSL usage.

    SSL

    The following procedure describes the SSL configuration that suits most databases. For some databases, you need to use another approach for a successful connection. You can see configuration examples for Cassandra and Heroku Postgres in the DataGrip documentation.

    Connect to a database with SSL

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. On the Data Sources tab, select a data source that you want to modify.

    3. Click the SSH/SSL tab and select the Use SSL checkbox.

    4. In the CA file field, navigate to the CA certificate file (for example, mssql.pem).

    5. In the Client certificate file field, navigate to the client certificate file (for example, client-cert.pem).

    6. In the Client key file field, navigate to the client key file (for example, client-key.pem).

    7. From the Mode list, select the verification mode:

      • Require: verifies that the server accepts SSL connections for this IP address and recognizes the client certificate.

      • Verify CA: verifies the server by checking the certificate chain up to the root certificate that is stored on the client.

      • Full Verification: verifies the server host to ensure that it matches the name stored in the server certificate. The SSL connection fails if the server certificate cannot be verified.

    8. To ensure that the connection to the data source is successful, click Test Connection.

      Connect to a database with SSL

    Disable SSL connection to a database

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. On the Data Sources tab, select a data source that you want to modify.

    3. Click the SSH/SSL tab and clear the Use SSL checkbox.

    4. Click Apply.

    Copy SSL settings from other data sources

    If you configured SSL settings for one data source, you can copy them for another data source.

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. On the Data Sources tab, select a data source that you want to modify.

    3. Click the SSH/SSL tab and select the Use SSL checkbox.

    4. Click the Copy from … link and select the configuration that you want to copy.

    SSH

    Secure Shell or SSH is a network protocol that is used to encrypt a connection between a client and a server.

    All created SSH connections are shared between all the data sources that you have in a project. If you do not want to share a connection between projects, select the Visible only for this project checkbox in the SSH connection settings.

    Connect to a database with SSH

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. Select a data source profile where you want to change connection settings.

    3. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

    4. Click the Add SSH configuration button (the Add SSH configuration).

    5. In the SSH dialog, click the Add button.

    6. If you do not want to share the configuration between projects, select the Visible only for this project checkbox.

    7. In Host, Username, and Port fields, specify your connection details.

    8. From the Authentication type list, you can select an authentication method:

      • Password: to access the host with a password. To save the password in PyCharm, select the Save password checkbox.

      • Key pair (OpenSSH or PuTTY): to use SSH authentication with a key pair. To apply this authentication method, you must have a private key on the client machine and a public key on the remote server. PyCharm supports private keys that are generated with the OpenSSH utility.

        Specify the path to the file where your private key is stored and type the passphrase (if any) in the corresponding fields. To have PyCharm remember the passphrase, select the Save passphrase checkbox.

      • OpenSSH config and authentication agent: to use SSH keys that are managed by a credentials helper application (for example, Pageant on Windows or ssh-agent on macOS and Linux).

      SSH and SSL settings of a data source

    Disable SSH connection to a database

    1. In the Database tool window ( ) , click the Data Source Properties icon The Data Source Properties icon.

    2. Select a data source profile where you want to change connection settings.

    3. Click the SSH/SSL tab and clear the Use SSH tunnel checkbox.

    4. Click Apply.

    Create the SSH tunnel with PuTTY (Windows)

    1. Download and run the latest version of the PuTTY SSH and Telnet client (download the client from https://www.putty.org/).

    2. In the PuTTY Configuration dialog, navigate to .

    3. In the Private key file for authentication field, specify the path to your private key file and click Open.

    4. In the command line window, specify the username that you use for the SSH tunnel and press Enter. Do not close the command line window.

    5. In the Database tool window ( ) , click the Data Source Properties icon the Data Source Properties icon on the toolbar.

    6. Select a data source profile where you want to change connection settings.

    7. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

    8. From the Auth type list, select OpenSSH config and authentication agent.

    9. In Proxy host, Proxy user, and Port fields, specify connection details.

    10. To ensure that the connection to the data source is successful, click Test Connection.

    Create the SSH tunnel with PuTTY (Windows)

    Create the SSH tunnel with Pageant (Windows)

    Pageant is an SSH authentication agent for PuTTY, PSCP, PSFTP, and Plink. Pageant stores your private key, and as long as it is running, it provides the unlocked private key to PuTTY or other tools like PyCharm. You can find the Pageant icon in the Windows taskbar.

    1. Download the latest version of Pageant (download the client from https://www.putty.org/).

    2. In the Windows taskbar, right-click the Pageant icon and select Add Key.

    3. In the Select Private Key File dialog, navigate to the private key file (the PPK file) and click Open.

    4. (Optional) Enter the private key passphrase and press Enter.

    5. In the Database tool window ( ) , click the Data Source Properties icon the Data Source Properties icon on the toolbar.

    6. Select a data source profile where you want to change connection settings.

    7. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

    8. From the Auth type list, select OpenSSH config and authentication agent.

    9. In Proxy host, Proxy user, and Port fields, specify connection details.

    10. To ensure that the connection to the data source is successful, click Test Connection.

    Create the SSH tunnel with Pageant (Windows)

    Create the SSH tunnel with the ssh-agent (macOS and Linux)

    Run all commands for ssh-agent in the command line.

    1. Ensure that ssh-agent is running.

      ssh-agent

    2. Add your key to the agent (in the following example, the key path is ~/.ssh/id_rsa).

      ssh-add ~/.ssh/id_rsa

    3. (Optional) On macOS, you can add -K option to the ssh-add command to store passphrases in your keychain. On macOS Sierra and later, you need to create the config file in ~/.ssh/ with the following text:

      Host *
      UseKeychain yes
      AddKeysToAgent yes
      IdentityFile ~/.ssh/id_rsa

      If you have other private keys in the .ssh directory, add an IdentityFile line for each key. For example, if the second key has the id_ed25519 name, add IdentityFile ~/.ssh/id_ed25519 as an additional line for the second private key.

    4. List all added keys.

      ssh-add -L

    5. In the Database tool window ( ) , click the Data Source Properties icon the Data Source Properties icon on the toolbar.

    6. Select a data source profile where you want to change connection settings.

    7. Click the SSH/SSL tab and select the Use SSH tunnel checkbox.

    8. From the Auth type list, select OpenSSH config and authentication agent.

    9. In Proxy host, Proxy user, and Port fields, specify connection details.

    10. To ensure that the connection to the data source is successful, click Test Connection.

    Create the SSH tunnel with the ssh-agent (macOS and Linux)

    Step 5. Write to us if you still need help

    Write to the PyCharm team

    • Email our team at pycharm-support@jetbrains.com. Describe your problem, and attach all available materials that can speed up troubleshooting (code samples, screenshots, logs, animations, videos, and other materials).

    For more information about other troubleshooting sources, see Troubleshooting.

    Last modified: 20 December 2022


    Table of Contents

    • The Problem
    • How it happens
      • Root Cause & Resolution
    • Summary
    • See Also

    The Problem

    SharePoint Products Configuration Wizard, when run for the first time, will create the Configuration DB and create a new SharePoint farm. In higher environment other than Dev it is a mandated practice to maintain two separate servers for application and
    database. SharePoint Products Configuration Wizard will be run in the application server where SharePoint is installed. In the configuration wizard, we will be specifying the back-end database where configuration database has to be created. So there would
    be a continuous network traffic exchange between the Application Server and the back-end Database Server when the Configuration wizard is run. When the Configuration Wizard runs for the first time there can be a chance that the below error pops up intermittently.

    In this article, we will see how we can overcome the issue.

    ↑ Return to Top


    How it happens

    During the SharePoint Installation time, Run the SharePoint Products Configuration Wizard and click Next.

    Click Yes to continue.

    We are setting up a new farm, hence select the radio button ‘Create a new server farm’ and click Next.

    Specify the database server name (VM02-SQL2016 in our case) in the field ‘Database Server’. The database access account used for the configuration will be ‘SPFarmAccount’ which will act as the farm account which is present in the domain.  Click
    Next.

    However, we may run into the problem which is shown below.

    On checking the SQL Server for the account permissions for SPSetupAccount(the account used for installing SharePoint), it was having ‘DBCreator’ and ‘Security Admin’ Privileges as mandated. As per the requirement, ‘SPFarmAccount
    (Farm Account) just needs to be a domain user. During the time of Configuration, the installer will automatically grant
    SPFarmAccount with DBOwner and SecurityAdmin privileges in the SQL Server. We don’t have to explicitly grant anything for
    SPFarmAccount.

    ↑ Return to Top


    Root Cause & Resolution

    After a lot of digging the root cause seems to be that SQL Server was not allowing any incoming connections. So we will have to enable it. Let’s see how to do it.

    Go to the SQL Server VM and spin up SQL Server 2016 Configuration Manager.

    Select SQL Server Network Configuration and click Protocols for MSSQLSERVER. TCP/IP is disabled by default. Enable it.

    After doing that we have to write a firewall rule that will enable incoming connections to 1433 port which is where SQL Server listens to. Go to Control Panel -> System and Security -> Windows Firewall. Select Advanced Settings option.

    Click ‘Inbound Rules’ and select ‘New Rule’ option.

      

    This will open up the inbound rule configuration wizard. Select the radio button ‘Port’ and click Next.

    Select the TCP radio button and specify the port 1433 in specific local ports text box.

    Specify the action that has to be taken as part of the rule, select ‘Allow the connection’ radio button.

    In profiles page, select the check box ‘Domain’ and click Next.

    Specify the name for the rule and click Finish.

    Make sure that you restart the SQL Server service for the changes to take effect.

    Now if we go back to the Configuration Wizard in the SharePoint VM and click Next, it will proceed to the next page without any exception. 

    Summary

    Thus we saw how to resolve the ‘Cannot connect to database master at SQL Server’ error that occurs during the installation of SharePoint Server 2016.

    ↑ Return to Top


    See Also

    This article can also be viewed at the below link :

    • Resolving ‘Cannot Connect To DataBase Master At SQL Server’ Error During SharePoint 2016 Installation

    Понравилась статья? Поделить с друзьями:
  1. Ошибка cannot find utcompiledcode record for this version uninstaller
  2. Ошибка cannot change visible in onshow or onhide
  3. Ошибка cannot call member function without object
  4. Ошибка cannot find the fakeroot binary
  5. Ошибка cannot be applied to given types