# 1、查看glibc版本
if [ $(rpm -qa glibc | awk -F "-" -v num=2.12 '{print($2 > num) ? 1 : 0}') -eq 1 ]; then echo -e "此版本符合要求"; fi
# 不符合要求就执行如下命令
yum install -y glibc
# 2、下载MySQL 卸载原来的数据库yum remove -y mariadb*
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz
# 3、解压缩文件
tar -zxvf mysql-5.7.28-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
# 4、重命名
mv mysql-5.7.28-linux-glibc2.12-x86_64 mysql
# 5、删除原来的my.cnf文件
rm -rf /etc/my.cnf
# 6、添加用户组
groupadd mysql
# 7、新建用户
useradd -r -g mysql mysql
# 8、设置mysql的拥有者
chown -R mysql:mysql /usr/local/mysql
# 9、修改/usr/local/mysql/support-files文件夹下的mysql.server
vim /usr/local/mysql/support-files/mysql.server
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
# 10、把mysql添加到系统服务
# 10.1、新建mysqld文件
vim /usr/lib/systemd/system/mysqld.service
# 10.2、添加如下内容
[Unit]
Description=mysql - database service
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
[Install]
WantedBy=multi-user.target
# 11、新建my.cnf文件
vim /etc/my.cnf
# 12、在my.cnf里添加如下内容
[client]
port = 3306
default-character-set = utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
port = 3306
server-id = 3306
max_connections = 2000
basedir = /usr/local/mysql
character-set-server = utf8
default-storage-engine=InnoDB
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
slow_query_log = 1
sort_buffer_size = 4M
join_buffer_size = 4M
log_timestamps = SYSTEM
read_rnd_buffer_size = 2M
slow_query_log_file = /usr/local/mysql/data/slow.log
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[mysqldump]
quick
max_allowed_packet = 32M
# 13、进入到/usr/local/mysql/bin目录下初始化(如果初始化过程中出错,可以根据依赖安装对应的包:numactl、libaio)
./mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --console
一定要记住最后一行打印的随机密码
用作首次登录
# 14、启动mysql服务
systemctl start mysqld
# 15、进入到/usr/local/mysql/bin目录下执行如下登录命令
./mysql -u root -p
# 16、登录mysql修改密码
set password=password('你的密码');
# 17、设置远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '你的密码';
# 18、刷新权限
FLUSH PRIVILEGES;
# 19、配置mysql环境变量
export MYSQL_HOME="/usr/local/mysql"
export PATH="$MYSQL_HOME/bin:$PATH"
# 20、下执行如下命令生效
source /etc/profile
如遇问题,请留言!