The MySQL Server we have running is configured via a configuration file. In fact, several or more configuration files.
To make navigating and viewing the files easier, let's change our current shell on the Ubuntu server to a
root shell (
#) in a more permanent basis:
Now we're doing everything as
root, so *be careful`!
Navigate to the location of the MySQL configuration:
If you did the previous projects and exercises, you'll know that the
/etc/ path is mostly used for configuration files for the software/services running on your system.
1 2 3 4 5 6 7 8 9 10
Our focus is on the
mysql.cnf file, the
mysql.conf.d/ directories. Let's look at the contents of the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
!includedir lines at the bottom that we're interested in. They tell us that the
mysql.cnf file doesn't contain any configuration at all, and in fact it's very likely coming from all the files found in two directories:
/etc/mysql/mysql.conf.d/. The term
includedir tells us the
dir or the
directory, as a whole, is being included.
Let's look in those directories:
ls -l conf.d/
1 2 3 4
ls -l mysql.conf.d/
1 2 3 4
Which file or files do we care about the most? We're concerned with the configuration of the MySQL Server process, so the file we want to investigate is the
mysqld.conf stands for
daemon, another word meaning
service. If you see a file like,
ntpd.conf or just
some-word followed by
d, and it's in
/etc/, then it's likely the configuration file for a
Let's look at the file's contents:
grep -v '#' mysql.conf.d/mysqld.cnf | grep -v '^$'
grep command is a command used for applying (very complicated, should you need it) pattern matching against text. Above I've used a simple match on the
# character, but in then I've matched on a regular expression:
^$. The manual page for
grep is (you guessed it):
I strongly suggest you review the manual page and get a feel for some simple
grep commands. It has a section on "Regular Expressions" and at the bottom, a section called
EXAMPLE that's also useful.
1 2 3 4 5 6 7 8
I've stripped everything else from the file so that we can focus on what's currently being set for the current server as it's running now. There are a lot of default values set behind the scenes, too.
There are two settings defined, above, of importance to us:
bind_address is the network IP address that MySQL Server will "bind" to. That is, MySQL Server will "bind" a network socket to the IP address
127.0.0.1 (the loopback address, also known by its hostname
TCP/3306. The port number
3306 isn't shown above because the default value is, in fact
3306. I suggest leaving this as is unless you have a (good) reason to change it. It adds very little to zero security benefit to change the default port.
And then we have the
log_error option, which has a value of
/var/log/mysql/error.log. Let's quickly look inside that file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
That's a lot of information. The only reason I want you to know about this file is simple: if there is an error or problem with your MySQL installation, this should contain information about the problem.
The concept of the log file or "error log" applies to a lot of other services and software too - they write log files we can use to get information about the services and what they're doing, or failing to do, as they operate. Not all services do this, but most of the services running most of the Internet (like MySQL, nginx, Apache, etc.) do write log files and you can even highly customise the logs to get less or more information out of them. The lesson here is: get to understand where a service or process is writing its log files to so you can investigate problems.
And of course the concept of the configuration file also applies to most other services you'll find in the wild. We've identified the location of the configuration file (or potentially files because of the
!includedir option) and then reviewed the file so that we know how MySQL Server is configured to run.
We don't need to change any MySQL configuration at this point in time. Next we're going to look at backing up a database and restoring it.