命令行输入rpm -qa|grep mariadb
命令行输入rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
https://dev.mysql.com/downloads/mysql/
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.29-linux-glibc2.12-x86_64.tar
命令行输入
mkdir software
tar -Jxvf mysql-8.0.29-linux-glibc2.12-x86_64.tar -C software/
cd /root/software
mv mysql-8.0.29-linux-glibc2.12-x86_64.tar mysql8
vi /etc/profile
在最下方添加
export MYSQL_HOME=/root/software/mysql8
export PATH=$PATH:$MYSQL_HOME/bin
yum install libaio
cd /root/software/mysql8
mkdir mysqldb
mkdir log
chmod -R 777 /root/software/mysql8/
[mysqld]
# 设置3306端口
port=3306
user=root
socket=/root/software/mysql8/mysql.sock
# 设置mysql的安装目录
basedir=/root/software/mysql8
# 设置mysql数据库的数据的存放目录
datadir=/root/software/mysql8/mysqldb
log-error=/root/software/mysql8/log/error.log
# 允许最大连接数
max_connections=10000
# 允许连接失败的次数。这是为了防止有人从该主机试图攻击数据库系统
max_connect_errors=10
# 服务端使用的字符集默认为UTF8
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8
[client]
# 设置mysql客户端连接服务端时默认使用的端口
port=3306
socket=/root/software/mysql8/mysql.sock
default-character-set=utf8
进入到mysql安装目录下
cd /root/software/mysql8/bin
MySQL初始化
./mysqld --initialize --console
初始化成功后产生的随机密码在/root/software/mysql8/log/error.log中,可以打开文件查看
cd /root/software/mysql8/support-files
./mysql.server start
vi /root/software/mysql8/support-files/mysql.server
修改如下位置信息
basedir=/root/software/mysql8
bindir=/root/software/mysql8/bin
if test -z "$datadir"
then
datadir=/root/software/mysql8/data
fi
sbindir=/root/software/mysql8/bin
libexecdir=/root/software/mysql8/bin
cd /root/software/mysql8/support-files
./mysql.server start
cp /root/software/mysql8/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl enable mysqld
输入MySQL初始化时在 /root/software/mysql8/log/error.log 中生成的随机密码,即可登录。
cd /root/software/mysql8/bin/
./mysql -u root -p
alter user 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';#将密码设置成123456
use mysql
update user set user.Host='%'where user.User='root';
flush privileges;
quit
service mysql restart
systemctl status mysql
//在防火墙中将3306端口开放
firewall-cmd --zone=public --add-port=3306/tcp --permanent
//重启防火墙
firewall-cmd --reload