# 1、卸载MariaDB
## 1.1 查看版本
[~]~ rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
## 1.2 卸载
[~]~ rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64
## 1.3 检查是否卸载干净
[~]~ rpm -qa|grep mariadb

# 2、安装MySQL
[~]~ cd /home/
## 2.1 wget下载
[home]~ wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
。。。。。。
## 2.2 解压
[home]~ tar -Jxvf mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz
。。。。。。
## 2.3 重命名
[home]~ mv mysql-8.0.20-linux-glibc2.12-x86_64 mysql8
## 2.4 移除
[home]~ rm mysql-8.0.20-linux-glibc2.12-x86_64.tar.xz

# 3、用户和用户组
## 3.1 创建用户组和用户
# 创建一个用户组:mysql
[home]~ groupadd mysql
# 创建一个系统用户:mysql,指定用户组为mysql
[home]~ useradd -r -g mysql mysql
## 3.2 数据目录
# 1、创建目录
[home]~ mkdir -p /home/mysql8/datas
# 2、赋予权限
# 更改属主和数组
[home]~ chown -R mysql:mysql /home/mysql8/datas
# 更改模式
[home]~ chmod -R 750

在mysql8文件夹中创建​​my.cnf​​文件,添加下面内容

[mysql]
# 默认字符集
default-character-set=utf8mb4
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /tmp/mysql.sock
# 安装目录
basedir = /home/mysql8
# 数据存放目录
datadir = /home/mysql8/datas/mysql
log-bin = /home/mysql8/datas/mysql/mysql-bin
innodb_data_home_dir =/home/mysql8/datas/mysql
innodb_log_group_home_dir =/home/mysql8/datas/mysql
#日志及进程数据的存放目录
log-error =/home/mysql8/datas/mysql/mysql.log
pid-file =/home/mysql8/datas/mysql/mysql.pid
# 服务端使用的字符集默认为8比特编码
character-set-server=utf8mb4
lower_case_table_names=1
autocommit =1

##################以上要修改的########################
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128

#query_cache_size = 128M
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535

binlog_format=mixed

binlog_expire_logs_seconds =864000

# 创建新表时将使用的默认存储引擎
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED

[mysqldump]
quick
max_allowed_packet = 16M

[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout
# 4、初始化MySQL
## 4.1 临时环境变量,关闭shell后失效,通常用于测试环境
[home]~ export PATH=$PATH:/home/mysql8/bin
## 4.2 初始化
[home]~ mysqld_safe --defaults-file=/home/mysql8/my.cnf &
## 4.3 启动MySQL
[home]~ mysql -uroot --skip-password
# 5、MySQL操作
## 5.1 修改密码
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> FLUSH PRIVILEGES;

## 5.2 设置允许远程登录
mysql> use mysql
mysql> update user set user.Host='%'where user.User='root';
mysql> flush privileges;
mysql>