Determining System glibc Version
Before downloading MySQL, identify the glibc version installed on your system:
rpm -qa | grep glibc
Common versions include glibc 2.17 and glibc 2.28. Download the corresponding MySQL package from the official website that matches your system's glibc version.
Pre-Installation Checks
Removing Conflicting Packages
Check for any existing MariaDB installations, which can conflict with MySQL:
rpm -qa | grep mariadb
If MariaDB packages are present, remove them with:
rpm -e --nodeps {package_name}
Installation Steps
Extracting the Package
Depending on the downloaded file format, use the appropriate extraction command:
tar -Jxvf mysql-8.0.38-linux-glibc2.17-x86_64.tar.xz
# or
tar -zxvf mysql-8.0.38-linux-glibc2.17-x86_64.tar.gz
Organizing the Installation Directory
Rename the extracted directory for convenience:
mv mysql-8.0.38-linux-glibc2.17-x86_64 /opt/mysql8
Relocate the directory to the desired installation path:
mv /opt/mysql8 /usr/local/
Create a data storage directory:
cd /usr/local/mysql8
mkdir data
Configuration File Setup
Edit or create the MySQL configuration file at /etc/my.cnf:
vim /etc/my.cnf
Add the following configuration parameters:
[mysqld]
port=3306
basedir=/usr/local/mysql8
datadir=/usr/local/mysql8/data
max_connections=10000
max_connect_errors=10
character-set-server=UTF8
default-storage-engine=INNODB
default_authentication_plugin=caching_sha2_password
[mysql]
default-character-set=utf8
[client]
port=3306
default-character-set=utf8
user=mysql
Database Initialization
Create a dedicated MySQL user and group:
groupadd mysql
useradd -rg mysql mysql
chown -R mysql:mysql /usr/local/mysql8/
Switch to the MySQL user and initialize the database:
su - mysql
cd /usr/local/mysql8
./bin/mysqld --initialize
Save the temporary password displayed during initialization for the next step.
Configuring the Startup Script
Navigate to the support files directory and update the startup script:
cd /usr/local/mysql8/support-files/
vi mysql.server
Modify these variables to match your installation paths:
basedir=/usr/local/mysql8
datadir=/usr/local/mysql8/data
Starting the MySQL Service
Start the databace server:
cd /usr/local/mysql8/support-files/
./mysql.server start
"SUCCESS!" indicates successful startup.
Resetting the Root Password
Connect to the MySQL server using the temporary password:
cd /usr/local/mysql8/
./bin/mysql -u root -p
Execute the password reset command:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
Setting Up Environment Variables
Add MySQL binaries to the system PATH by editing /etc/profile:
vim /etc/profile
Append the folowing lines:
export PATH=$PATH:/usr/local/mysql8/bin
Apply the changes:
source /etc/profile
Copy the startup script to the system init directory:
cp /usr/local/mysql8/support-files/mysql.server /etc/init.d/mysqld
This enables service management commends:
service mysqld start
service mysqld stop
service mysqld restart