WordPress 'Error establishing a database connection' - wordpress

I am trying to start my 1st project in WordPress and put this data
Database Name : wp-project-1
DB_USER : root
DB_PASSWORD : ``
DB_HOST : localhost
Table Prefix : wp_
And in my wp-config-sample.php:
define( 'DB_NAME', 'wp-project-1' );
/** MySQL database username */
define( 'DB_USER', 'root' );
/** MySQL database password */
define( 'DB_PASSWORD', '' );
/** 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', '' );
But it says error like this when I submit them:
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.
Are you sure you have the correct username and password?
Are you sure you have typed the correct hostname?
Are you sure the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.
Here I am using xampp server, and my xampp port number is 3307 (I change that cause 3306 was busy every time.)
How can I fix it?

on xampp you can open control panel where it says apache hit the config select php ini and find the following
mysqli.default_port=

Please change your wp-config-sample.php file to wp-config.php

Related

WordPress Error establishing a database connection MySQL on non-default port

I'm trying to install wordpress on my localhost with XAMPP. My Apache module is on ports 80,443 and my MySQL module is on port 3307 (default is 3306). I can't start installing wordpress. After entering localhost/wordpress in my browser there apears error "Error establishing a database connection". I don't have wp-config.php file i guess it creates after starting installation which i can't start
I tried changing wp-config-sample.php but it looks like it doesn't change anything i also tried creating wp-config.php on my own and changing DB details there
You have to change config.php not config-sample.php.
define( 'DB_NAME', 'your_dbname' );
define( 'DB_USER', 'your_dbuser' );
define( 'DB_PASSWORD', 'your_dbpasw' );
define( 'DB_HOST', 'localhost:3307' );
That's all you need. Just append ":" after localhost (or your machine ip address/host name)
Having a database connection issue would mean there's a "wp-config.php" file being used, and the credentials are incorrect -- hostname, port, credentials, or possibly not having a database created yet.
During an initial setup, WordPress will create the wp-config.php file with the MySQL credentials, when the connection is a success. If you're not getting a setup page, review your "wp-config.php" file, or delete all of the contents and start over with a new WordPress download. Extract the zip/tar.gz archive, and move the contents in the "wordpress/" folder into your site's DocumentRoot.
You can also test your MySQL credentials with this command:
mysql -h localhost -P 3307 -u DatabaseUsername -p
The uppercase "P" is for port, and the lowercase "p" is for password. If entering the password at the prompt is successful, check that you've got a database with show databases;.

phpMyAdmin Cannot log in to the MySQL server on Centos 7

I installed mysql-community-server-8.0.13-1.el7.x86_64 on Centos 7 with Nginx, and added the phpMyAdmin to manage the databases but I keep getting error Cannot log in to the MySQL server from phpMyAdmin. I've tried the following and have been struggling for a few days now:
Changed some of the parameters (suggested on stackoverflow) located on /etc/phpMyAdmin/config.inc.php like the following but no luck:
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'socket';
$cfg['Servers'][$i]['socket'] = '/var/lib/mysql/mysql.sock';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
I've tried mysql shell, and I'm able to login with root and other users. But, I have no idea why it fails on phpMyAdmin. Please help and thanks!
I was able to resolve this by doing the following:
(I should mention that this solution works for MySQL 8.0.13 and phpMyAdmin 4.8.4 - Both, latest version today)
1- I edited config.inc.php with these server parameters (only):
/*** This is needed for cookie based authentication to encrypt password in
cookie. Needs to be 32 chars long. */
$cfg['blowfish_secret'] = 'generate_your_blowfish_secret_32_chars';
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
2- On MySQL terminal
//Create a new user:
mysql> CREATE USER 'user'#'localhost' IDENTIFIED BY 'your_password';
//Grant all privileges:
mysql> GRANT ALL PRIVILEGES ON *.* To 'user'#'localhost' WITH GRANT OPTION;
//Flush all privileges:
mysql> FLUSH PRIVILEGES;
//Change authentication_string with password:
mysql> ALTER USER user IDENTIFIED WITH mysql_native_password BY
'your_password';
//Login with the new user and password!
This should allow you to login into phpMyAdmin. I hope this help!
This work for me :
sudo mysql
ALTER USER 'root'#'localhost' IDENTIFIED WITH mysql_native_password BY 'YourNewPassword';
On CentOS 7, I had to:
uncomment the "default-authentication-plugin=mysql_native_password" line in /etc/my.cnf
(then systemctl restart mysqld)
ALTER USER 'user'#'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';
A minor tweak on the accepted answer from Jacman above. I had tried everything else, but was missing the 'WITH mysql_native_password' clause

How to setup Wordpress with https://box.scotch.io/?

I have setup scotch box and now trying to setup WordPress with scotch box how would I go by doing this please.
I have recently set this up.
To set up Wordpress, place the Wordpress install files inside the scotch/public folder that is created when you first run scotch.io
You will then need to ssh into your vagrant box, and set up a new MySQL database. You can import a dump via the command line, or export/import using Sequel like I did.
Even though mod_rewrite is already enabled in scotch.io, I found it helpful to restart the apache2 server in the vagrant box.
Once that's done - you should be able to navigate to 192.168.33.10 on your browser to see your install.
Set the wp_config.php database host to localhost.
I found the following code great for getting permalinks working, place this at the top of your wp_config file:
$s = empty($_SERVER['HTTPS']) ? '' : ($_SERVER['HTTPS'] == 'on') ?
's' : '';
$port = ($_SERVER['SERVER_PORT'] == '80') ? '' : (":".$_SERVER['SERVER_PORT']);
$url = "http$s://" . $_SERVER['HTTP_HOST'] . $port;
define('WP_HOME', $url);
define('WP_SITEURL', $url);
unset($s, $port, $url);
If you get a Database access error - this is a good sign you're on the right track, you need to put in the user: root / pass: root details fro the vagrant web host to access the database inside the box.

Error Establishing a Database Connection - Using Postgres / pg4wp

I've solved this problem when faced with a MySQL setup, but I seem to be falling short when we use PG.
Issue: Error establishing a database connection
Here's my wp-config.php:
// ** Heroku Postgres settings - from Heroku Environment ** //
$db = parse_url($_ENV["DATABASE_URL"]);
if($_SERVER["SERVER_NAME"]==="localhost") {
define('DB_NAME','finpipe_dev_db');
/** MySQL database username */
define('DB_USER','ilia');
/** MySQL database password */
define('DB_PASSWORD','ilia');
/** MySQL hostname */
define('DB_HOST','localhost');
} else {
// ** Heroku Postgres settings - from Heroku Environment ** //
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME',trim($db["path"],"/"));
/** MySQL database username */
define('DB_USER',$db["user"]);
/** MySQL database password */
define('DB_PASSWORD',$db["pass"]);
/** MySQL hostname */
define('DB_HOST',$db["host"]);
}
/** 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','');
Here's my output from being inside the Postgres console:
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
--------------------+----------+----------+-------------+-------------+-----------------------
finpipe_dev_db | ilia | UTF8 | en_CA.UTF-8 | en_CA.UTF-8 |
I've even done ALTER USER ilia WITH PASSWORD 'ilia';
And yet, still getting hit with Error Establishing...
What's going on?
This error you are getting is probably because PostgreSQL isn't accepting connections. Please check pg_hba.conf and postgresql.conf files in your PostgreSQL instance directory, you might have to configure them in order to be able to access your database.
Try to configure the following and test, if it works, you'll need to find the correct configuration (this one allows all)
pg_hba.conf
# IPv4 local connections:
host all all 0.0.0.0/0 md5
postgresql.conf
listen_addresses = '*'

Your PHP installation appears to be missing the MySQL extension which is required by WordPress - for multiple instance

My system is running 2 MySQL instance
One is running on port 3306 another on port 3307
Now I want to connect my WordPress to MySQL which is running on port 3307
But I am getting error when I try to access index page - Your PHP installation appears to be missing the MySQL extension which is required by WordPress.
Please let me guide how to resolve the problem.
Edit the definition of DB_HOST in your wp-config.php file by adding :3307. From the documentation:
If your host uses an alternate port number for your database you'll
need to change the DB_HOST value in the wp-config.php file to reflect
the alternate port provided by your host.
For localhost
define( 'DB_HOST', 'localhost:3307' );
Other
define( 'DB_HOST', 'mysql.example.com:3307' );
Replace 3307 with whatever port number your host gives you.
Solution 1:
Check your php.ini and make sure that you have extension=php_mysql.dll un-commented.
Solution 2:
You can use the following library if you do not have mysql_connect enabled but have PDO enabled:
https://github.com/AzizSaleh/mysql
Create a new file: wp-content/db.php and place this code in it (update your path to mysql with path to your extracted folder):
<?php
$pathToMySQL = 'C:\\xampp\\htdocs\\mysql\\';
require_once($pathToMySQL . 'MySQL_Definitions.php');
require_once($pathToMySQL . 'MySQL.php');
require_once($pathToMySQL . 'MySQL_Functions.php');

Resources