Can't connect to mysql by tcp immediately after a fresh installation

Collapse

Unconfigured Ad Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • Delaney martin
    Senior Member
    • Jun 2022
    • 187

    Can't connect to mysql by tcp immediately after a fresh installation

    VPS Hosting
    Hi, I am trying to connect mysql using this:
    mysql -h 127.0.0.1 -P 3306 --protocol=tcp -uroot

    It always returns an error:
    MySQL Error 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)

    Thanks in advance
  • Rachel S
    Senior Member
    • Apr 2022
    • 185

    #2


    The error may be caused by MySQL not running or not listening to the specified port.


    Check if MySQL is running:

    sudo systemctl status mysql # Run this to check the status of MySQL:


    sudo systemctl start mysql # If not, start MySQL

    Verify MySQL is listening on port 3306


    sudo netstat -tulnp | grep mysql


    or

    sudo ss -tulnp | grep mysql


    output:

    tcp LISTEN 0 50 127.0.0.1:3306 *:* users("mysqld",pid,fd))


    If MySQL is not listening on 127.0.0.1, check your MySQL configuration. Check MySQL configuration (my.cnf or mysqld.cnf)


    sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf #Opens the MySQL configuration file


    ** Look for this line: bind-address = 127.0.0.1 **

    Make sure it is not set to 0.0.0.0 or commented out.

    Restart MySQL after making changes:

    sudo systemctl restart mysql


    If MySQL is running and listening, try connecting again:

    mysql -h 127.0.0.1 -P 3306 --protocol=tcp -uroot -p

    Comment

    Working...
    X