Skip to content

Instantly share code, notes, and snippets.

@zongwu233
Last active April 18, 2022 07:15
Show Gist options
  • Save zongwu233/0e6a44857d4c258646e16b160ab53543 to your computer and use it in GitHub Desktop.
Save zongwu233/0e6a44857d4c258646e16b160ab53543 to your computer and use it in GitHub Desktop.
install mysql5.7 in CentOS7 ,and add basic config.
#!/bin/bash
sudo rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
# update GPG-key
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
#sudo yum repolist all | grep mysql | grep enabled
#sudo yum -y install mysql-community-server
sudo yum install -y \
mysql-community-libs-5.7.35-1.el7.x86_64 \
mysql-community-server-5.7.35-1.el7.x86_64 \
mysql-community-common-5.7.35-1.el7.x86_64 \
mysql-community-client-5.7.37-1.el7.x86_64 \
mysql-community-libs-compat-5.7.35-1.el7.x86_64
echo " modify /etc/my.cnf ,add character utf8"
FILE=/etc/my.cnf
if [[ -f "$FILE" ]]; then
sudo rm -rf "$FILE"
fi
cat<<'EOF'>$FILE
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
[client]
[mysql]
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
collation-server = utf8mb4_general_ci
init-connect='SET NAMES utf8mb4'
character-set-server=utf8mb4
default-time_zone = '+8:00'
EOF
echo " start msyqld service "
sudo systemctl start mysqld
sudo systemctl enable mysqld
echo "You need change default password! ,find old password in follow line:"
cat /var/log/mysqld.log | grep -i 'temporary password'
mysql_secure_installation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment