I have been on many projects where the existing or legacy stack could not be altered, but a significant new level of functionality requiring the latest version of MySQL was required. This is where the Software Collection Library (SCL) shines!. SCL packages exist to enable parallel versions of PHP, Apache, Python etc. to operate along side legacy or default CentOS/RedHat PHP, Apache, Python etc. stacks.
Here is a procedure that I have used many times to set up a new MySQL 5.7 instance, running on an alternate port on a CentOS server that may already have a legacy version of MySQL installed and operating. When completed, the legacy instance will continue to operate as normal (on port 3306), while a new MySQL 5.7 instance shall be available on port 3316.
- Basic Linux administration and command familiarity
- If MySQL is already installed on the system, you know the port it is currently communicating on
- You have sudo access privileges on the Linux server. In this example, I am using CentOS.
- See disclaimer
1. Installation Procedure
- See if yum-utils is installed, as this is required for the current SCL library and we shall use yum-config-manager:
yum info yum-utils
- Check the “repo” and other output to see if it is installed. If required, install yum-utils:
yum install yum-utils -y
- Install the base CentOS SCL components:
yum install centos-release-scl -y
- Enable the CentOS SCL through yum-config-manage. You may be prompted to accept the signing key and other configurations.
yum-config-manager --enable rhel-server-rhscl-7-rpms
- Install MySQL 5.7 SCL
yum install rh-mysql57 -y scl enable rh-mysql57 bash
The process above shall install three MySQL 5.7 directory structures:
a. SCL “CHEROOT” skeleton structure is installed in /opt/rh
b. MySQL 5.7 data and logs are installed in: /var/opt/rh/rh-mysql57/
c. MySQL 5.7 cnf and related config files are installed in: /etc/opt/rh/rh-mysql57
- Make a copy of default cnf, as you will be changing it to function with existing MySQL.old instance
NOTE: The root my.cnf calls the instance my.cnf.d/rh-mysql57-mysql-server.cnf
cd /etc/opt/rh/rh-mysql57/my.cnf.d cp rh-mysql57-mysql-server.cnf rh-mysql57-mysql-server.cnf.oldinstalldefault
- Please consider the following as suggestions to standup a basic MySQL 5.7 development environment, as there are may sites and articles dedicated to configuring proper large-scale production instances.
Perhaps it will be the subject of a later posting.Configure rh-mysql57-mysql-server.cnf to work along side MySQL.old and provide needed defaults:
a. NOTE: You may wish to change the data directory, as this is where your data structure and data files shall reside.
b. under [mysqld], comment default socket file config and create new line as shown
c. under [mysqld], bind to port 3316
d. Under under [mysqld], set character-set-server to utf8 and collation-server to your collation of choice. In our example, I chose utf8_unicode_ci
e. under [mysqld_safe], set timezone=UTC
# # These groups are read by MySQL server. # Use it for options that only the server (but not clients) should see # See the examples of server my.cnf files in /usr/share/mysql/ # this is read by the standalone daemon and embedded servers [server] # this is only for the mysqld standalone daemon # Settings user and group are ignored when systemd is used. # If you need to run mysqld under a different user or group, # customize your systemd unit file for mysqld/mariadb according to the # instructions in http://fedoraproject.org/wiki/Systemd [mysqld] # if you change the datadir path, make sure you # migrate-tar existing structure and content with # existing permissions and ownership or service will not start datadir=/var/opt/rh/rh-mysql57/lib/mysql # We address new socket path below. Make sure new path has # same permissions and ownership as the default path #socket=/var/lib/mysql/mysql.sock log-error=/var/opt/rh/rh-mysql57/log/mysql/mysqld.log pid-file=/var/run/rh-mysql57-mysqld/mysqld.pid #PaulsDevBlog Suggested Basic Dev-environment mysqld Settings. #You will need to verify these and adjust to your needs. #See following for mysqld 5.7 options #https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html #https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_collation_server socket=/var/lib/mysql57/mysql.sock skip-external-locking #This is the port that this instance will run on. #You will need to verify this port is valid and not already in use port=3316 #This is the magic to have MySQL answer on all IPs present and localhost bind-address=0.0.0.0 #Setting standard collation is a good practice #You will need to verify these and adjust to your needs. character-set-server=utf8 collation-server=utf8_unicode_ci [mysqld_safe] #PaulsDevBlog Suggested Basic Dev-environment mysqld_safe Settings for TimeZone. #You will need to verify these and adjust to your needs. #See following for mysqld 5.7 options #https://dev.mysql.com/doc/refman/5.7/en/mysqld-safe.html timezone=UTC # this is only for embedded server [embedded]
- chmod the MySQL 5.7 socket file directory so the native mysql client can attach to socket file and connect:
chmod -R 777 /var/lib/mysql57
2. Initial Startup of New SCL MySQL 5.7 Instance
The SCL MySQL instances will have different init services defined. So, the commands to start/stop the service are different
- On CentOS 7.x:
systemctl start rh-mysql57-mysqld.service One CentOS 6.x:
service rh-mysql57-mysqld start
3. Making SCL MySQL 5.7 Auto-start with CentOS
- On CentOS 7.x:
systemctl enable rh-mysql57-mysqld.serviceOne CentOS 6.x:
chkconfig –levels 235 rh-mysql57-mysqld on
4. Troubleshooting initial SCL MySQL 5.7 startup and failures
- To see status or troubleshoot, check MySQL error log:
5. Running SQL MySQL 5.7 Secure Installation Utility
- Look through first few lines of mysql.log to find your initial password; there should be a line similar to:
“root@localhost is created with an empty password ! Please consider switching off the –initialize-insecure option.“
- IMPORTANT: When initially logging in as root, the password should be blank. See above.
IMPORTANT: With the SCL instance, you will need to specify port and socket settings on the local MySQL client tools to connect. The socket directory will need to be accessible to local user accounts, and defined within the CNF. See above.
cd /opt/rh/rh-mysql57/root/usr/bin/ ./mysql_secure_installation --port=3316 --socket=/var/lib/mysql57/mysql.sock
Typical Responses to the MySQL Secure Installation Setup are:
Would you like to setup VALIDATE PASSWORD plugin? [password complexity is up to you for dev, a must for prod and compliance]
New/Re-enter Root Password
Remove anonymous users? Y
Disallow root login remotely? Y
Remove test database and access to it? Y
Reload privilege tables now? Y
6. Running SCL MySQL 5.7 Utilities
Remember that with the SCL instance, you will need to specify port and socket settings on the local MySQL client tools:
/opt/rh/rh-mysql57/root/usr/bin/mysql -u root -p --port=3316 --socket=/var/lib/mysql57/mysql.sock mysql -u root -p --port=3316 --socket=/var/lib/mysql57/mysql.sock
That’s it! The SoftwareCollections.org (SCL) Library provides many distributions; this is one I frequently use. Please Like and Link, thanks.