One-Click Installation of MySQL on Linux

Preparing Installation Package

mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz

Download and install the package to /usr/local/soft, this path should match the one in the script file

Write the script fileinstall_mysql.sh (CentOS version)

The content of the file is as follows:

#! /usr/bin/bash## Fully automated source code compilation and installation for any versionif [ ! -d "/usr/local/soft" ]then
echo "Directory does not exist, please create the directory and place the installation package here"
exit
fi
# MySQL installation
cd /usr/local/soft
if [ ! -f mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz ]then
echo "File does not exist"
exit
fi

ar -xvf mysql-8.0.28-linux-glibc2.12-x86_64.tar.xz
mv mysql-8.0.28-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/
mkdir -p /usr/local/mysql/data
groupadd mysql
useradd -g mysql mysql
chown -R mysql:mysql /usr/local/mysql/
mkdir mysql_install_db
chmod 777 ./mysql_install_db
mkdir /var/log/mariadb
touch /var/log/mariadb/mariadb.log
chown -R mysql:mysql  /var/log/mariadb/
# Initialize database
cd mysql
bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --lower-case-table-names=1 --console
# Modify my.cnf configuration file
touch /etc/my.cnf
echo "[mysqld]\nbasedir = /usr/local/mysql   \ndatadir = /usr/local/mysql/data\nsocket = /usr/local/mysql/mysql.sock\ncharacter-set-server=utf8\nport = 3306\nsql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES\nlower_case_table_names=1\n[client]\nsocket = /usr/local/mysql/mysql.sock\ndefault-character-set=utf8" >>/etc/my.cnf
# Add MySQL service to system services
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
# 1.7. Configure global environment variables
echo "export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib" >>/etc/profile
echo "export PATH" >>/etc/profile
source /etc/profile
# Start MySQL service and change password
service mysql start
ln -s  /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5
echo "Connecting to MySQL"
echo "The initial password is empty, just press enter"
sql="ALTER user 'root'@'localhost' IDENTIFIED BY 'admin@123';
use mysql;
update user set host='%' where user='root' limit 1;
flush privileges;
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'admin@123';
flush privileges;"
mysql -u root -p -e "${sql}"
echo "Operation successful"
echo "Database installation completed"

Note that the default password after installation is admin@123. If installing a different version, you need to modify the filename in the script accordingly.

Place the prepared script file in /usr/local/soft (if modified, please use your own file path) for execution (it can actually be placed elsewhere, but without the installation package, it must be placed in/usr/local/soft), and remember to grant permissions.

Technical accumulation, meeting is fate

One-Click Installation of MySQL on Linux

Leave a Comment