0

I am using a VPS Ubuntu 20.04 in a2 hosting. I am trying to set up my mysql database but I am getting some error. I am doing this through a SSH. I installed mysql using

sudo apt-get install mysql-server mysql-client

and it installed just fine. But when I try to run

sudo mysql_secure_installation

it throws me this error

Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (111)

I have tried to reinstall mysql-server, but without success. I have noticed some errors:

  1. In my /etc/mysql/my.cnf file, it looks like is missing some code, I just have this: enter image description here

It doesn't have any information about the socket.

  1. My /var/run/mysqld/mysqld.sock file was not created when I installed the db. Not even the folder /var/run/mysqld was created. I tried to create both, but it still doesn't worked. In my example, the files are being created in a wrong way ou not even being created. I don't know why this is happening.

FIle: /etc/mysql/mysql.conf.d/mysqld.cnf

#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user        = mysql
# pid-file  = /var/run/mysqld/mysqld.pid
# socket    = /var/run/mysqld/mysqld.sock
# port      = 3306
# datadir   = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir        = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1
mysqlx-bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size     = 16M
# max_allowed_packet    = 64M
# thread_stack      = 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log        = 1
# slow_query_log_file   = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id     = 1
# log_bin           = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db      = include_database_name
# binlog_ignore_db  = include_database_name

Is there anything I am missing? If someone could help me I would be grateful. Thank you!

Pedro
  • 25
  • 4
  • Does this answer your question? [Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)](https://stackoverflow.com/questions/5376427/cant-connect-to-local-mysql-server-through-socket-var-mysql-mysql-sock-38) – Tangentially Perpendicular Sep 18 '21 at 18:23
  • But in my case my mysql.sock is not creating and my my.cnf is incomplete. These two files are wrong by default. – Pedro Sep 18 '21 at 18:43
  • Your `my.cnf` file is not incomplete. It includes two paths to directories with further files that will be included in the configuration for both `mysql` and `mysqld`. You will find the socket details in one of those files. – Tangentially Perpendicular Sep 18 '21 at 21:07
  • Oh. I read the file from /etc/mysql/mysql.conf.d and find the file mysqld.cnf which have some information. And it also have the path to the socket. What should I do now? The content of this file shouln't have been in the /etc/mysql/my.cnf ? I edited the post and put the file there. – Pedro Sep 18 '21 at 21:59
  • Editing the `my.cnf` file might not be harmful, but isn't needed. MySQL will include the extra files automatically. That's the purpose of the `!includedir` directive. – Tangentially Perpendicular Sep 18 '21 at 22:03
  • Ok. But how can I make it generate the socket file in /var/run/mysqld/mysqld.sock. Because it's throwing me the error saying that can't connect to the socket file. I tried to create this file, but it is a blank file. Is there somewhere I can find this file, so I can add it manually? If not, how can I force it to be generated? Because when I do the mysql-server installation it doesn't create it by default. – Pedro Sep 18 '21 at 22:21

1 Answers1

0

For anyone who have the same error, I solve this by reinstalling my entire OS. My ubuntu version was 20.04 and I installed the 18.04 version. This solved for me.

Pedro
  • 25
  • 4