Question

Cannot secure my MySQL

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: https://www.digitalocean.com/community/tutorials/how-to-secure-mysql-and-mariadb-databases-in-a-linux-vps

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 “127.0.0.1”.

bind-address = 127.0.0.1

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
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

#
# * 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

-WDG


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:

/etc/mysql/conf.d
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
/etc/mysql/mysql.conf.d
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:

  1. sudo systemctl restart mysql

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

/etc/mysql/mysql.conf.d/50-server.cnf

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.