Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error establishing a database connection when cloning repo #159

Open
josuevalrob opened this issue Oct 30, 2018 · 17 comments
Open

Error establishing a database connection when cloning repo #159

josuevalrob opened this issue Oct 30, 2018 · 17 comments

Comments

@josuevalrob
Copy link

  • VersionPress version: 4 - beta
  • WordPress version: 4.9.8
  • OS, web server, PHP: Mac Mojave, PHP 7.1.9, MySQL 5.7, MAMP
  • Git version: 2.17

I am working on different environments, all of them works perfectly fine, so maybe is a problem with my system.

After cloning the repository, creating the config file pointing into an empty database, I try to run the Restore Site command.

wp vp restore-site --siteurl=http://localhost/clinica/ --require=wp-content/plugins/versionpress/src/Cli/vp.php

But it doesn't work, and gives me this error:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Database Error</title>

</head>
<body>
	<h1>Error establishing a database connection</h1>
</body>
</html>

The MySQL credentials are fine. I had tried to include the port on the MySQL hostname, but nothing happened. Any idea?.

@borekb
Copy link
Member

borekb commented Oct 31, 2018

Hi @josuevalrob, can you check the wp-config.php file to see if DB credentials are really correct? When you create a plain PHP script (without WordPress) that connects using these credentials, does the connection succeed?

@josuevalrob
Copy link
Author

Hi @josuevalrob, can you check the wp-config.php file to see if DB credentials are really correct? When you create a plain PHP script (without WordPress) that connects using these credentials, does the connection succeed?

No, it gives me errors doing the wp config create, I had to solve it with sudo

@zauker
Copy link

zauker commented Oct 31, 2018

@josuevalrob at first I think you must try a MySQL connection with the mysql command in your terminal, doing this we can understand if the problem is MySQL or Versiopress.
Did you try to change the connection host from 'localhost' to '127.0.0.1'?

@zauker
Copy link

zauker commented Oct 31, 2018

Hi @josuevalrob, can you check the wp-config.php file to see if DB credentials are really correct? When you create a plain PHP script (without WordPress) that connects using these credentials, does the connection succeed?

No, it gives me errors doing the wp config create, I had to solve it with sudo

It seems you have a wrong file or folder permissions setted.

@josuevalrob
Copy link
Author

@josuevalrob at first I think you must try a MySQL connection with the mysql command in your terminal, doing this we can understand if the problem is MySQL or Versiopress.
Did you try to change the connection host from 'localhost' to '127.0.0.1'?

I tried that, and works fine.
mysql -u root -p connect and once inside I was able to create the database. Other wordpress site are working fine.

Hi @josuevalrob, can you check the wp-config.php file to see if DB credentials are really correct? When you create a plain PHP script (without WordPress) that connects using these credentials, does the connection succeed?

No, it gives me errors doing the wp config create, I had to solve it with sudo

It seems you have a wrong file or folder permissions setted.

I will test that

@josuevalrob
Copy link
Author

josuevalrob commented Oct 31, 2018

@zauker @borekb
Hello, again.
My problem persists.

I had changed the permissions and after running the wp config create everything went very well.
I don't have problems accessing into MYSQL.

Another clue is:

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port          | 8889  |
+---------------+-------+

If my database is working on port 8889. Is this a problem?.

In the last hours, I was able to clone the development site into my machine and installed it manually, (changing route variables from the database, etc). The site is working, and I can clone and push code with git. But when I try to use wp vp pull it gives me this error:

Error: Error establishing a database connection. This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at localhost. This could mean your host’s database server is down.

This is my site URL: http://localhost:8888/clinica

And this is the command that I tried to run in the morning:
wp vp restore-site --siteurl='http://localhost/clinica/' --require=wp-content/plugins/versionpress/src/Cli/vp.php

I tried changing the localhost port, to 8889 in the wp-config.php file, but nothing change...

Any idea?

BTW: I have installed AcquiaDevDesktop (is like another Mamp). But one friend of mine has it too and doesn't have any problem.

@borekb
Copy link
Member

borekb commented Nov 1, 2018

From what you say, your site URL is not http://localhost/clinica/ but http://localhost:8888/clinica. The port matters greatly.

@josuevalrob
Copy link
Author

I had tried including the port, but nothing change...
MacBook-Pro:clinica josue$ wp vp restore-site --siteurl=http://localhost:8888/clinica --require=wp-content/plugins/versionpress/src/Cli/vp.php

MacBook-Pro:clinica josue$ wp vp restore-site --siteurl=http://localhost:8888/clinica --require=wp-content/plugins/versionpress/src/Cli/vp.php
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Database Error</title>

</head>
<body>
	<h1>Error establishing a database connection</h1>
</body>
</html>

@borekb
Copy link
Member

borekb commented Nov 1, 2018

Could you please post your wp-config.php (with the password removed)? There are a couple of suspicious things, for example, you say that your database runs on port 8889 which is an unusual port for the database (8xxx are usually web servers). Also, you said you tested connection with mysql -u root -p which is connecting to port 3306, not 8889. Another suspicious thing is that your command-line command returns a HTML response – which web server returns it? (WP-CLI is not a web server.)

Thanks.

@josuevalrob
Copy link
Author

josuevalrob commented Nov 2, 2018

Simple:

// ** MySQL settings ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'clinica' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', 'root' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

And yes, I can run:

MacBook-Pro:clinica josue$ mysql -u root -proot
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 

But once inside, I check for the ports:

mysql> select user();
+----------------+
| user()         |
+----------------+
| root@localhost |
+----------------+
1 row in set (0.01 sec)
mysql> SELECT @@port; 
+--------+
| @@port |
+--------+
|   8889 |
+--------+

With all this, I went into the system preferences from MAMP, and yeah, the apache port was set to 8888and the MySQL was 8889. I don't know why... So I set it up to default, port 80and 3306.

Now, the main route is: http://localhost/clinicaand checking the mysql port I got the 3306.

But the problem perssist. I am trying this:
wp vp restore-site --siteurl=http://localhost/clinica --require=wp-content/plugins/versionpress/src/Cli/vp.php
And get the same response:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Database Error</title>

</head>
<body>
	<h1>Error establishing a database connection</h1>
</body>
</html>

How do I know which web server returns the HTML response??

@josuevalrob
Copy link
Author

all the wp-config.php

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://codex.wordpress.org/Editing_wp-config.php
 *
 * @package WordPress
 */

// ** MySQL settings ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'clinica' );

/** MySQL database username */
define( 'DB_USER', 'root' );

/** MySQL database password */
define( 'DB_PASSWORD', 'root' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

/**
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',          'UR@-gfuNO5GH5PSFdAh)^STnBO}Sl*t^B}*jp=jOcu~ssMSCfW 7ii&Yu!RFE_bu' );
define( 'SECURE_AUTH_KEY',   '|ye-s.Y(cM#6*c87s]Xv*2X^I$kJQ]CM8Zmf+AMDWK5+qss;l50[WYjM@^2q_c|h' );
define( 'LOGGED_IN_KEY',     '|0SH[KGCIBB(YE{ktStrtQVCOrZ5?x2OPM.*/Z<tr0>S!ehSEbC;!S2;C_AkJ4pa' );
define( 'NONCE_KEY',         'k;+o]uZ(F]fBF06P$Fb$[z_`R=rtKjgx|zX,T>m%rv]2S+xGYz)wy0ht1`rc@WKI' );
define( 'AUTH_SALT',         ';`H9bdC(vMtg<~Ge-4$`R$jYkwnz;skPIjL@$A-AdZc&4JaA-0`;%I7y?v-GQ%WR' );
define( 'SECURE_AUTH_SALT',  'E~7t83-BzXs ?gN%bMz[,@/pyS2ZsIRTk3gdFD 3<`s<6LdXlSO+,^Ae.07-w1$F' );
define( 'LOGGED_IN_SALT',    ']Fi}p4F^9}eV_[D~lM!DEH~>@*NeJP*2%eDLzh(Y=?^_(qp(NtkH#eY(&T$WiB{+' );
define( 'NONCE_SALT',        '?{MUY!~Wa1}Z}=_. pjDHqdR;RS)L>37scQ%/=5-B97m2Sb<fPz|gPU6du8U}A>Z' );
define( 'WP_CACHE_KEY_SALT', '7@!g}}D2l/<nbQ]Lh1tf-2ha<8hXR4`^i3 $bqiR]Jl;alt0zM.9gUIG#U&.q|j}' );

/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';




/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) )
	define( 'ABSPATH', dirname( __FILE__ ) . '/' );

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

@borekb
Copy link
Member

borekb commented Nov 5, 2018

There are still suspicious things, for example, you say that your MAMP is configured to run Apache on port 8888 while your URL http://localhost/clinica means port 80. Two completely separate web servers can handle those so maybe you've got more web servers installed locally? Same can be true for database servers.

You could try downloading fresh & clean WordPress, extract it to a folder under your web root, copy your wp-config.php there and see if it connects, and on which URL it runs.

@pavelevap
Copy link
Collaborator

Hi @josuevalrob, did you manage to solve this issue?

@josuevalrob
Copy link
Author

no.

Maybe is something about my localhost configuration.

I am working with docker right now.

@IHIutch
Copy link

IHIutch commented May 1, 2019

Following up here, having a similar issue.

wp vp restore-site --siteurl='http://localhost:8888/' --require=wp-content/plugins/versionpress/src/Cli/vp.php

returns

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Database Error</title>

</head>
<body>
	<h1>Error establishing a database connection</h1>
</body>
</html>

But I know my database params are correct because I'm seeing the wordpress install screen

@itservice-haase
Copy link

Any news? I have the same issue. Can install wordpress with the same wp-config.php but not run vp restore. Get an "Error establishing a database connection".

I run Mamp Pro on default ports of the services. (HTTP 80, 443; MYSQL 3306)

@tariuk
Copy link

tariuk commented Mar 31, 2020

Same error here. Database connection works fine, but wp vp restore-site gives "Error establishing a database connection". Tried all the methods outlined everywhere I could find them, but can't escape that error. I'd LOVE any help on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants