Cannot secure my MySQL

January 11, 2017 221 views
MySQL Ubuntu 16.04

Hey Everyone, I really do apologise if this has already been asked. I am however a complete noob and cannot seem to solve this.

I am following this tutorial:

I have got to the part that asks me to type in this command:

sudo nano /etc/mysql/my.cnf

Then it says: The first setting that we should check is the "bind-address" setting within the "[mysqld]" section. This setting should be set to your local loopback network device, which is "".

bind-address =

However, all I get is this ouput:

The MySQL database server configuration file.
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
# 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

# * IMPORTANT: Additional settings that can override those from this file!
#   The files must end with '.cnf', otherwise they'll be ignored.

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

Can someone tell me what I am supposed to do? I cannot seem to get past this stage to secure my mysql. There does not appear to be a [mysqld] section :/

Thank you


2 Answers

Sorry for the confusion. In some newer distributions the configuration is split into multiple files in order to make it easier to manage.

The setting you are looking for is most likely going to be in


Those last two lines in the file you shared are telling the process to include all the configuration files on those two directories into my.cnf at runtime.

The tutorial you linked (How To Secure MySQL and MariaDB Databases in a Linux VPS), is a bit older older tutorial. However guides there are still relevant but there are changes in MySQL config structure for newer version.

For older versions (AFAIK prior to MySQL 5.7 and Ubuntu 16.04), all config things were in one file - /etc/mysql/my.cnf. That got changed, and now config are splitted in multiple files. The important part of /etc/mysql/my.cnf:

#   The files must end with '.cnf', otherwise they'll be ignored.

!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

As you see it will look for .cnf files in following directories: /etc/mysql/conf.d/ and /etc/mysql/mysql.conf.d. When you list structure of them, you'll see following:

total 8
-rw-r--r-- 1 root root  8 Jul 14 16:09 mysql.cnf
-rw-r--r-- 1 root root 55 Jul 14 16:09 mysqldump.cnf
total 8
-rw-r--r-- 1 root root 3028 Jul 14 16:09 mysqld.cnf
-rw-r--r-- 1 root root   21 Jul 11  2016 mysqld_safe_syslog.cnf

The file you need is /etc/mysql/mysql.conf.d/mysqld.cnf. Once you open it, in comment you'll see:

# The MySQL database server configuration file.

And there will be [mysql] part with bind-address in it.
Once you change it, don't forget to restart MySQL for changes to take effect:

  • sudo systemctl restart mysql
  • Thank you for your reply. I am getting the right file now. However I cannot seem to start that last command

    please see this image:

    When I type it, nothing happens.

    • This is because you are still in text editor. Delete line you added:

      $ sudo systemctl restart mysql

      save file and exit text editor.
      As you are using nano, press CTRL+X on your keyboard type y and press ENTER to confirm that you'll write to that file.
      Once you exit editor, you can execute command to restart MySQL.

      • Thank you so much. I have one more question.

        For some reason when I logout and then log back in again it does not ask for my password.

        it just logs me straight in

        • Are you talking about Droplet login? If you are using SSH keys this is normal, as with SSH key you are not required to enter password.

Have another answer? Share your knowledge.