1
votes

I'am facing "Error establishing a database connection" by setting up wordpress on macOS. Here is my steps:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress_database_***' );

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

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

/** 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', '' );
  • Create db + user by commandline
$ sudo mysql -u admin -p
mysql> CREATE DATABASE db_name;
mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'db_pass';
mysql> GRANT ALL PRIVILEGES ON db_name.* TO 'db_user'@'localhost';
mysql> FLUSH PRIVILEGES;
mysql> exit
$ sudo mysql.server restart
$ sudo nginx // start nginx 
  • Finally, I load mydomain.com (config in vhosts). And be always getting issues ("Error establishing a database connection")

Anyone experienced, pease give me some helps, Thanks

1

1 Answers

1
votes

Finally, I found the solution.

  • With mysql 8.0x, the create user with mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED BY 'db_pass';, will assign authentication type as 'caching_sha2_password'.

  • I just change the command to create user as mysql> CREATE USER 'db_user'@'localhost' IDENTIFIED WITH mysql_native_password BY 'db_pass';

Now my wordpress site work perfectly.