Installing MySQL 5.7.28 on CentOS 7

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.

  1. 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
    
  2. Remove existing MariaDB or MySQL installations:

    rpm -qa | grep mariadb
    rpm -qa | grep mysql
    

    Uninstall detected packages:

    yum remove mariadb-xxx mysql-xxx
    
  3. 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
    
  4. Create a symbolic link:

    ln -s /opt/mysql-5.7.28 /usr/local/mysql
    
  5. Configure system user and permissions:

    useradd -s /bin/false -M mysql
    chown -R mysql:mysql /opt/mysql-5.7.28
    
  6. 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
    
  7. Initialize the database:

    cd /usr/local/mysql
    bin/mysqld --initialize --user=mysql
    

    If dependencies are missing, install autoconf:

    yum install -y autoconf
    

    Ensure log directories exist:

    mkdir /usr/local/mysql/logs
    chown mysql:mysql /usr/local/mysql/logs
    

    Note the temporary root password generated during initialization.

  8. Set up the service script:

    cp support-files/mysql.server /etc/init.d/mysqld
    
  9. Start MySQL:

    service mysqld start
    

    If 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
    
  10. Add MySQL to the system path:

    Edit /etc/profile:

    export MYSQL_HOME=/usr/local/mysql
    export PATH=$PATH:$MYSQL_HOME/bin
    

    Apply changes:

    source /etc/profile
    
  11. Secure and configure access:

    Log in with the temporary password:

    mysql -u root -p
    

    Change the password:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword';
    FLUSH PRIVILEGES;
    

    Enable remote access:

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'RemotePassword';
    
  12. Service management commands:

    service mysqld start    # Start service
    service mysqld stop     # Stop service
    service mysqld restart  # Restart service
    service mysqld status   # Check status
    

Tags: MySQL centos Database Installation Linux MySQL 5.7

Posted on Mon, 01 Jun 2026 00:02:44 +0000 by michaelphipps