MySQL is a widely used open-source relational database. Installation steps can vary between versions; this guide details the process for MySQL 5.7.28.
-
Obtain MySQL 5.7.28 from the official archives. Download the 64-bit Linux version:
wget https://downloads.mysql.com/archives/community/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -
Remove existing MariaDB or MySQL installations:
rpm -qa | grep mariadb rpm -qa | grep mysqlUninstall detected packages:
yum remove mariadb-xxx mysql-xxx -
Extract the archive and relocate:
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /opt mv /opt/mysql-5.7.28-linux-glibc2.12-x86_64 /opt/mysql-5.7.28 -
Create a symbolic link:
ln -s /opt/mysql-5.7.28 /usr/local/mysql -
Configure system user and permissions:
useradd -s /bin/false -M mysql chown -R mysql:mysql /opt/mysql-5.7.28 -
Create and edit
/etc/my.cnf:[mysqld] log-bin=/usr/local/mysql/logs/mysql-bin.log expire-logs-days=14 max-binlog-size=500M server-id=1 basedir=/usr/local/mysql datadir=/usr/local/mysql/data socket=/usr/local/mysql/mysql.sock user=mysql default-storage-engine=InnoDB character-set-server=utf8 lower_case_table_names=1 explicit_defaults_for_timestamp=true [mysqld_safe] log-error=/usr/local/mysql/mysql-error.log pid-file=/usr/local/mysql/mysqld.pid [client] socket=/usr/local/mysql/mysql.sock [mysql] default-character-set=utf8 socket=/usr/local/mysql/mysql.sock -
Initialize the database:
cd /usr/local/mysql bin/mysqld --initialize --user=mysqlIf dependencies are missing, install autoconf:
yum install -y autoconfEnsure log directories exist:
mkdir /usr/local/mysql/logs chown mysql:mysql /usr/local/mysql/logsNote the temporary root password generated during initialization.
-
Set up the service script:
cp support-files/mysql.server /etc/init.d/mysqld -
Start MySQL:
service mysqld startIf log file errors occur, create and permission the file:
touch /usr/local/mysql/mysql-error.log chown mysql:mysql /usr/local/mysql/mysql-error.log -
Add MySQL to the system path:
Edit
/etc/profile:export MYSQL_HOME=/usr/local/mysql export PATH=$PATH:$MYSQL_HOME/binApply changes:
source /etc/profile -
Secure and configure access:
Log in with the temporary password:
mysql -u root -pChange the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; FLUSH PRIVILEGES;Enable remote access:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'RemotePassword'; -
Service management commands:
service mysqld start # Start service service mysqld stop # Stop service service mysqld restart # Restart service service mysqld status # Check status