Home > Blockchain >  Can't connect to mysql on localhost:3306?
Can't connect to mysql on localhost:3306?

Time:10-01

seems like a pretty basic question. but i can't find any duplicate answers.

can't connect to mysql.

I've reinstalled mysql-server. Doesn't make any difference.

MySql appears to be listening on a socket...

dara@laptop-20-04:~/Desktop$ netstat -an | grep mysql
unix  2      [ ACC ]     STREAM     LISTENING     690638   /var/run/mysqld/mysqlx.sock
unix  2      [ ACC ]     STREAM     LISTENING     690639   /var/run/mysqld/mysqld.sock

but i can't login as root

dara@laptop-20-04:~/Desktop$ sudo /etc/init.d/mysql stop
Stopping mysql (via systemctl): mysql.service.
dara@laptop-20-04:~/Desktop$ sudo mysqld --skip-grant-tables &
[3] 119080
dara@laptop-20-04:~/Desktop$ mysql -u root mysql
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (111)
^G[2]-  Exit 1                  sudo mysqld --skip-grant-tables

my mysql.cnf

dara@laptop-20-04:.../mysql/conf.d$ cat mysql.cnf
[mysql]
bind-address = localhost

[client]
protocol = tcp

also tried changing bind-address = 127.0.0.1

mysql version

dara@laptop-20-04:.../mysql/conf.d$ mysql --version
mysql  Ver 8.0.26-0ubuntu0.21.04.3 for Linux on x86_64 ((Ubuntu))

help!

CodePudding user response:

As you said, MySQL is listening only on the socket it seems and you force your client to use TCP. Try the following:

mysql -u root -S /var/run/mysqld/mysqld.sock

CodePudding user response:

so basically the log files were showing a lock file error. i should have provided this detail originally. you can check your log files for ubuntu at...

tail /var/log/mysql/error.log

2021-10-01T10:51:37.787720Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.26-0ubuntu0.21.04.3) starting as process 145495 2021-10-01T10:51:37.796108Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2021-10-01T10:51:37.820698Z 1 [ERROR] [MY-012574] [InnoDB] Unable to lock ./ibdata1 error: 11

this was a misconfiguration of apparmor. I found a solution here...

stackoverflow mysql solution

you first id all the mysql processes by

$ ps aux | grep mysql

then you kill all those processes. where pid is the process id

sudo kill <pid>

then you fix app armor

$ apt install apparmor-profiles

then mysql starts no problems

sudo systemctl start mysql
  • Related