Install MySql 5.7.33 via RPM under Linux
- Download MySql related packages
- Relevant packages have dependencies and need to be installed in sequence
rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rpm
- Initialize the password (the password is empty after the initial completion)
mysqld --initialize-insecure --user=mysql
- Start MySql
systemctl start mysqld
- Login and update password and grant remote connection
mysql -u root --skip-password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURPASSWD';
grant all privileges on *.* to 'root'@'%' IDENTIFIED BY '2660c1dd1942844f';
update mysql.user set grant_priv='Y' where user='root';
flush privileges;
- Related one-click installation scripts
Before installation, you need to put the relevant rpm package and the script in the same directory
function IN_MYSQL () {
local PACK_PARH=$(cd $(dirname $0); pwd)
cd $PACK_PATH
pkill mysql
sleep 5
for i in `rpm -qa | grep msyql`;do rpm -e --nodeps $i;done
for i in `rpm -qa | grep mariadb`;do rpm -e --nodeps $i;done
\rm -rf /var/lib/mysql /etc/my.cnf /var/log/mysqld.log
rpm -ivh mysql-community-common-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.33-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.33-1.el7.x86_64.rpm
# Init mysql
mysqld --initialize-insecure --user=mysql
systemctl start mysqld
mysql -u root --skip-password -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '2660c1dd1942844f';grant all privileges on *.* to 'root'@'%' IDENTIFIED BY '2660c1dd1942844f';update mysql.user set grant_priv='Y' where user='root';flush privileges;"
# Add a power-on boot
systemctl enable mysqld
ps aux | grep mysql | grep -v grep
if [ $? -eq 0 ]; then
echo '=========== mysql install successed ================'
else
echo '=========== mysql install failed ===================='
fi
}
IN_MYSQL
Summary of relevant knowledge:
1. Since version 5.7.6, the data directory and root account are initialized by mysqld --initialize, and versions before 5.7.6 are initialized by mysql_install_db;
2. Using --initialize will generate a random initial value for the root account Password, we can use the command: mysql -u root -p, and then enter the password to log in to MySQL. Using –initialize-insecure will not generate a random initial password for the root account, we can use the command: mysql -u root --skip-password to log in to MySQL directly;
3. When mysqld displays the following error message:
[ERROR] --initialize specified but the data directory exists. Aborting, please execute rm -rf /var/lib/mysql