MySQL Data base Installation
To install MySQL on a CentOS 7 system, follow these steps:
[root@server ~]# wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
[root@server ~]# yum -y install mysql57-community-release-el7-9.noarch.rpm
[root@server ~]# cd /etc/yum.repos.d/
[root@server ~]# yum -y install mysql-server
Starting the MySQL Service
After installation, start the MySQL service with the following command:
[root@server ~]# systemctl start mysqld
Retireving the Initial Root Password
The MySQL installation generates a temporary root password. You can find it in the log file:
[root@server ~]# grep 'temporary password' /var/log/mysqld.log
# The root@localhost: *** shown in the output is the initial login password
Connecting to MySQL
Use the following command to connect to the MySQL server with the root account:
[root@server ~]# mysql -u root -p
[root@server ~]# Enter password:
Setting a New Password
Once connected to MySQL, set a new password for the root user:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('your_new_password');
Checking Password Policy Settings
Verify the current password policy configuration:
mysql> SHOW VARIABLES LIKE 'validate_password%';
Modifying Password Policy
If needed, adjust the password policy to be less restrictive:
mysql> SET GLOBAL validate_password_policy = LOW;
Setting Minimum Password Length
Configure the minimum password length to 6 characters:
mysql> SET GLOBAL validate_password_length = 6;
Applying New Password
Set a new password that meets the policy requirements:
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('secure_password');
Enabling Remote Access
To allow remote connecsions to the MySQL server:
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'secure_password' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES;
Complete MySQL Uninstallation on CentOS 7
Identifying MySQL-related RPM Packages
First, list all MySQL-related packages installed on the system:
[root@server ~]# rpm -qa | grep -i mysql
mysql57-community-release-el7-9.noarch
mysql-community-client-5.7.32-1.el7.x86_64
mysql-community-libs-5.7.32-1.el7.x86_64
mysql-community-libs-compat-5.7.32-1.el7.x86_64
mysql-community-common-5.7.32-1.el7.x86_64
mysql-community-server-5.7.32-1.el7.x86_64
Removing MySQL Packages
Uninstall all identified MySQL packages using yum:
[root@server ~]# yum remove mysql57-community-release-el7-9.noarch
[root@server ~]# yum remove mysql-community-client-5.7.32-1.el7.x86_64
[root@server ~]# yum remove mysql-community-libs-5.7.32-1.el7.x86_64
[root@server ~]# yum remove mysql-community-libs-compat-5.7.32-1.el7.x86_64
[root@server ~]# yum remove mysql-community-common-5.7.32-1.el7.x86_64
[root@server ~]# yum remove mysql-community-server-5.7.32-1.el7.x86_64
Finding MySQL-related Directories
Locate any remaining MySQL directories on the system:
[root@server ~]# find / -name mysql
/etc/selinux/targeted/active/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql
Removing Residual Directories
Delete all remaining MySQL-related directories:
[root@server ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql
[root@server ~]# rm -rf /var/lib/mysql
[root@server ~]# rm -rf /var/lib/mysql/mysql
[root@server ~]# rm -rf /usr/share/mysql
Removing MySQL Log File
Delete the MySQL log file to prevent issues with future installations:
[root@server ~]# rm -rf /var/log/mysqld.log
# If this file is not removed, it may cause problems with new MySQL installations