MySQL 5.7.26 Installation Procedure on Linux
Create the target directory structure. The server binaries will reside under /usr/local/mysql, and the data files will be placed in /mysql/data.
mkdir -p /usr/local/mysql /mysql/data
Download the MySQL community server tarball and extract it to the installation directory. Rename the unpacked folder for convenience.
cd /usr/local
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
tar -zxvf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 mysql
Set up the operating system user and group that will own the MySQL process. Assign ownership of the installation directory to this user.
groupadd mysql
useradd -r -g mysql mysql
chown -R mysql:mysql /usr/local/mysql
Install the libaio library if it is not already present, then run the server initializasion. The --initialize flag generates a temporary root password, which appears in the console output.
yum -y install libaio
cd /usr/local/mysql
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/data
Prepare supplementary directories required by the configuration file: a slow query log, an error log, and storage locations for redo and undo logs. All of them must be owned by the mysql user.
mkdir -p /mysql/logs
touch /mysql/logs/slow.log /mysql/logs/error.log
chmod 644 /mysql/logs/slow.log /mysql/logs/error.log
mkdir /mysql/redolog /mysql/undolog
chown -R mysql:mysql /mysql
Create the configuration file /etc/my.cnf (or place it in the default location expected by the service script). The following is a minimal but production-oriented set of parameters. Adjust buffer sizes and paths to match you're environment.
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server-id = 37
port = 3306
basedir = /usr/local/mysql
datadir = /mysql/data
socket = /tmp/mysql.sock
skip_name_resolve = 1
character-set-server = utf8
collation-server = utf8_general_ci
init_connect = 'SET NAMES utf8'
lower_case_table_names = 1
max_connections = 400
max_connect_errors = 1000
explicit_defaults_for_timestamp = true
max_allowed_packet = 128M
interactive_timeout = 300
wait_timeout = 300
tmp_table_size = 1G
max_heap_table_size = 1G
query_cache_size = 512M
query_cache_type = 1
sort_buffer_size = 4M
binlog_cache_size = 16M
max_binlog_cache_size = 256M
back_log = 100
log_error = /mysql/logs/error.log
slow_query_log = 1
slow_query_log_file = /mysql/logs/slow.log
log_queries_not_using_indexes = 1
log_throttle_queries_not_using_indexes = 5
log_slow_slave_statements = 1
long_query_time = 0.5
expire_logs_days = 14
log-bin = mysql-bin
binlog_format = ROW
binlog_row_image = minimal
master_info_repository = TABLE
relay_log_info_repository = TABLE
log_slave_updates
relay_log_recovery = 1
slave_skip_errors = ddl_exist_errors
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
innodb_buffer_pool_size = 1G
innodb_log_buffer_size = 128M
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_io_capacity = 500
innodb_lock_wait_timeout = 30
innodb_buffer_pool_dump_pct = 40
innodb_log_group_home_dir = /mysql/redolog
innodb_undo_directory = /mysql/undolog
innodb_log_files_in_group = 3
innodb_log_file_size = 1024M
innodb_undo_tablespaces = 0
innodb_print_all_deadlocks = 1
[mysqldump]
quick
max_allowed_packet = 128M
[mysql]
no-auto-rehash
[mysqld_safe]
open-files-limit = 28192
Copy the provided startup script to /etc/init.d/ and edit the basedir and datadir variables to match the actual paths.
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
sed -i 's|^basedir=$|basedir=/usr/local/mysql|' /etc/init.d/mysqld
sed -i 's|^datadir=$|datadir=/mysql/data|' /etc/init.d/mysqld
Launch the database service and verify it is listening on port 3306.
/etc/init.d/mysqld start
telnet 127.0.0.1 3306
Add the MySQL binaries to the system PATH so that client tools can be invoked without absolute paths.
echo 'export PATH=$PATH:/usr/local/mysql/bin' >> /etc/profile
source /etc/profile
Log in using the temporary password that was printed during initialization and set a new root password. Then grant remote access for administrative tasks (restrict the host as appropriate).
mysql -uroot -p
ALTER USER USER() IDENTIFIED BY 'StrongPassword';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.%' IDENTIFIED BY 'StrongPassword';
FLUSH PRIVILEGES;
Open the MySQL port in the firewall. On CentOS 7 or later with firewalld:
firewall-cmd --add-port=3306/tcp --permanent --zone=public
firewall-cmd --reload
For older releases using iptables, append the following rule to /etc/sysconfig/iptables and restart the service:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
Enable automatic startup on system boot.
chkconfig --add mysqld
When configuring replication, retrieve the master's binary log coordinates with SHOW MASTER STATUS on the source server. On the replica, stop the slave threads and execute the CHANGE MASTER TO command with the appropriate values, then restart replication.
CHANGE MASTER TO
MASTER_HOST='192.168.0.2',
MASTER_PORT=3306,
MASTER_USER='repl',
MASTER_PASSWORD='repl_pass',
MASTER_LOG_FILE='mysql-bin.000021',
MASTER_LOG_POS=154;
START SLAVE;
A dedicated replication user should be created on the master:
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.0.3' IDENTIFIED BY 'repl_pass';
Always inspect the error log (/mysql/logs/error.log) if the server fails to start or initialisation fails; common issues include permission problems, missing directories, or an incorrect my.cnf.