0

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!

Myuser03
  • 85
  • 11

2 Answers2

0

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
lefred
  • 111
  • 3
  • thanks. how come setting bind-address = 127.0.0.1 doesn't fix it though? I thought the IP address forced mysql to listen over TCP? Or am i mistaken? – Myuser03 Sep 30 '21 at 12:33
0

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
ouflak
  • 2,458
  • 10
  • 44
  • 49
Myuser03
  • 85
  • 11