0

I am trying to setup wordpress locally on my Ubuntu 20.04. I have installed all the prerequisites as per tutorial, when i try localhost, it says "Error establishing a database connection".

So, i tried to create database user name and password again with the following details

mysql> CREATE DATABASE lwl;
Query OK, 1 row affected (0.17 sec)

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lwl                |
| mysql              |
| performance_schema |
| sys                |
| wordpress          |
+--------------------+
6 rows in set (0.00 sec)

mysql> CREATE USER 'lwluser'@'localhost' IDENTIFIED BY 'lwl1234';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL ON lwl.* TO 'lwluser'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.01 sec)

mysql> ^DBye

Updated wp-config.php file with the latest values

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

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

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

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

Still i am getting the same error. Then i wrote a simple php file to check

<?php
$link = mysqli_connect('localhost', 'lwluser', 'lwl1234', 'lwl');
if (!$link) {
        die('Could not connect: ' . mysqli_error());
}
echo 'Connected successfully';
mysqli_close($link);
?>                                                                                                               
~   

This failed with 'could not connect' but did not gave any sql error. Can you guys please help me here. I am beginner in web development

Update: sql is running on 3306

$ netstat -tln
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN     
tcp6       0      0 :::33060                :::*                    LISTEN     
tcp6       0      0 :::80                   :::*                    LISTEN     
tcp6       0      0 :::1716                 :::*                    LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:631                 :::*                    LISTEN

I also tried the below and passing the "lwl1234" works

$ mysqlshow -u lwluser -p
Enter password: 
+--------------------+
|     Databases      |
+--------------------+
| information_schema |
| lwl                |
+--------------------+
md.jamal
  • 4,067
  • 8
  • 45
  • 108
  • Is MySQL running on 3306 port? – Sameer Kumar Jain Sep 27 '20 at 04:46
  • Yes. Added the netstat -tln output – md.jamal Sep 27 '20 at 04:50
  • Make sure you properly setup firewall for mysql. Somehow, firewall is the issue. – Kimsea Sok Sep 27 '20 at 04:57
  • How to check firewall settings – md.jamal Sep 27 '20 at 05:07
  • You have an error. [`mysqli_error()`](https://www.php.net/manual/en/mysqli.error.php) needs one argument. Please consider switching error mode on instead. [How to get the error message in MySQLi?](https://stackoverflow.com/a/22662582/1839439) Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) – Dharman Sep 27 '20 at 12:37
  • Does this answer your question? [Should we ever check for mysqli\_connect() errors manually?](https://stackoverflow.com/questions/58808332/should-we-ever-check-for-mysqli-connect-errors-manually) – Dharman Sep 27 '20 at 12:38
  • I got the following error: Error: Unable to connect to MySQL. Debugging errno: 2054 Debugging error: The server requested authentication method unknown to the client – md.jamal Sep 27 '20 at 13:10
  • alter user 'lwluser'@'localhost' identified with mysql_native_password by 'lwl1234'; – md.jamal Sep 27 '20 at 13:15
  • The above solved the issue – md.jamal Sep 27 '20 at 13:15

0 Answers0