Skip to content

Instantly share code, notes, and snippets.

@jamesdavidson
Last active January 4, 2019 03:51
Show Gist options
  • Save jamesdavidson/e1ef7d61800349a2e2d98bceed36a582 to your computer and use it in GitHub Desktop.
Save jamesdavidson/e1ef7d61800349a2e2d98bceed36a582 to your computer and use it in GitHub Desktop.
Notes from automating the installation of MySQL on CentOS.
So, what did I try?
Well, first I tried to find a CMS that didn't need MySQL. Painful.
Then, I tried installing MySQL. They have made this very hard to
automate.
Then, I tried running MySQL in a Docker container. The first annoying
thing here was that I needed a specific version of Docker's API but that
also meant a specific version of the Python library and adding
api_version=1.19 in the Ansible script too. The second annoying thing
was that the Docker module(s) for Ansible basically don't work. The
third annoying thing is internal networking... do Docker containers gets
hostnames or addresses?
Now, I'm back trying to install vanilla MySQL. For years, MySQL has had
a blank root password as the default configuration. They recently
decided to generate a pseudo-random password instead and stash it in
/root/.mysql_secret . Alternatively, one can start up mysqld with
--skip-grant-tables and then mess around with permissions then.
Alternatively, there's a program called mysql_secure_installation which
is wizard that guides you through the process.
How am I meant to automate that? Using expect(1) or something?
Even when you do extract the temporary password, you can only use it
from the command-line, not from the Python library.
Exception message: (1862, 'Your password has expired. To log in you must
change it using a client that supports expired passwords.')
However, if you change your password to be the temporary password then
it's all good!
sudo mysqladmin --password={{ mysql_root_password }} password {{
mysql_root_password }}
Even then, this requires two runs. Why?!
@jamesdavidson
Copy link
Author

If you are trying to get a simple localhost MySQL database server up and running then the following setup commands seem to work on CentOS 7.5 as of January 2019:

yum install mysql-server
sudo -u mysql /usr/sbin/mysqld --initialize-insecure
echo 'MYSQLD_OPTS="--bind-address=127.0.0.1"' >> /etc/sysconfig/mysql

If you have this Yum config available in /etc/yum.repos.d/mysql57-community.repo :

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/
gpgcheck=0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment