Error connecting to MySQL - ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

Asked 1 years ago, Updated 1 years ago, 39 views

After MySQL was introduced into AWS Lightsail, I tried to log in to MySQL first, but I received the following error:

Enter current password for root (enter for none): 
ERROR 2002(HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2)
Unable to connect to the server as root user, giving up.
Cleaning up...

I made it because mysql.sock is missing.

$sudo touch/var/lib/mysql/mysql.sock

This time, the error number will be changed and there will be no permission.

$mysql-u root
ERROR 2002(HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(13)

So I'll give you permission.

$sudo chmod777/var/lib/mysql/mysql.sock

This time, you will receive an error saying that you cannot connect to the server further.

$mysql-u root
: Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock' (111)

At the same time, you are prompted to delete the file /var/lib/mysql/mysql.sock that you created first.

$sudo service mysqld start
Socket file /var/lib/mysql/mysql.sock exists.
The file/var/lib/mysql/mysql.sock is not a socket file, which is suspicious.
Please, remove/var/lib/mysql/mysql.sock manually to start the service.

Delete it.

$sudorm/var/lib/mysql/mysql.sock

This will return to the starting point.

ERROR2002(HY000): Can't connect to local MySQL server through socket'/var/lib/mysql/mysql.sock'(2)

The my.cnf file contains:

 [mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links = 0
character-set-server=utf8
innodb_buffer_pool_size=256M

[client]
socket=/var/lib/mysql/mysql.sock
port = 3306

[mysqld_safe]
log-error=/var/log/mysqld.log

The log looks like this.

 2020-08-230 09:25:26 4206 [Note] Plugin'FEDERATED' is disabled.
^G/usr/libexec/mysql56/mysqld: Can't find file:'./mysql/plugin.frm' (errno:13-Permission denied)
2020-08-230 09:25:26 4206 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
2020-08-230 09:25:26 4206 [Note] InnoDB: Using atomics to ref count buffer pool pages
2020-08-230 09:25:26 4206 [Note] InnoDB: The InnoDB memory heap is disabled
2020-08-230 09:25:26 4206 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builds
2020-08-230 09:25:26 4206 [Note] InnoDB: Memory barrier is not used
2020-08-2309:25:26 4206 [Note] InnoDB: Compressed tables use zlib 1.2.8
2020-08-230 09:25:26 4206 [Note] InnoDB: Using Linux native AIO
2020-08-230 09:25:27 4206 [Note] InnoDB: Using CPU crc32 instructions
2020-08-2309:25:27 4206 [Note] InnoDB: Initializing buffer pool, size=256.0M
2020-08-230 09:25:27 4206 [Note] InnoDB: Completed initialization of buffer pool
2020-08-230 09:25:27 4206 [ERROR] InnoDB:./ibdata1 can't be opened in read-write mode
2020-08-230 09:25:27 4206 [ERROR] InnoDB: The system tablespace must be writable!
2020-08-230 09:25:27 4206 [ERROR] Plugin'InnoDB' init function returned error.
2020-08-230 09:25:27 4206 [ERROR] Plugin'InnoDB' registration as a STORAGE ENGINE failed.
2020-08-230 09:25:27 4206 [ERROR] Unknown/unsupported storage engine:InnoDB
2020-08-230 09:25:27 4206 [ERROR] Aborting

mysql

2022-09-30 15:38

1 Answers

Do you understand the difference between the mysql command and the mysqld command? It only looks like I'm doing something useless

mysqldSpecifications that create a socket where mysqld is /var/lib/mysql/mysql.sock when the MySQL daemon body starts.The mysql command then attempts to connect to this socket.So if you create sudo touch/var/lib/mysql/mysql.sock and other normal files, naturally the connection to the socket will fail, resulting in an error.Therefore, it is natural for me to ask you to delete the file.

Cannot connect to mysql.sock =mysql.sock socket not generated by mysqld =mysqld failed to start, so what you should see now is log-error=/var/log/mysqld.log.

You had another question.The log has been reprinted, so I'll read it.The fatal wound is

2020-08-2309:25:27 4206 [ERROR] InnoDB:./ibdata1 can't be opened in read-write mode

InnoDB:./ibdata1 cannot be opened in readable mode.

Now that I'm delusional about the reason,

  • UsermysqlGroupmysql Missing/Disabled/Permission Settings Bad
  • MYSQL_DATADIR is missing/configuration is bad
  • MYSQL_DATADIRThe ibdata1 file is missing
  • MYSQL_DATADIR does not have read/write permission for user/groupmysql
  • ibdata1 file does not have read/write permission for user/groupmysql
  • MYSQL_DATADIRibdata1 is corrupted due to insufficient capacity, etc.
  • Someone deleted it because there were so many files I didn't know (not just humans, but security software quarantined it)

If you're just delusional, you can spread it out, but only the questioner knows the truth.

Our hpux server contains the old mysql and specifies MYSQL_DATADIR=/home/mysql/data.

#cd/home/mysql/data
# ls-libdata1
-rw-rw ----1 mysql mysql 45651584 Aug 5 16:38 ibdata1
#

The user mysql group mysql has ibdata1 readable and correctly started mysqld as shown in .


2022-09-30 15:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.