安装过程:
0. mysql安装包下载
链接:https://pan.baidu.com/s/1CGbehC7s7Bb93a_kCpz_Zw 提取码:nyde
1. 查看Linux中是否已安装mysql
ps -ef | grep mysql
2. 查看当前安装的mariadb包(安装新版mysql之前,我们需要将系统自带的mariadb-lib卸载)
rpm -qa | grep mariadb 查看当前安装的mariadb包
rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 强制卸载过程1的运行结果
3. 在mysql安装包路径下解压安装包
tar -xvf mysql-8.0.15-1.el7.x86_64.rpm-bundle.tar
4. 安装mysql的rpm软件包
rpm -ivh mysql-community-common-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-embedded-compat-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.15-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.15-1.el7.x86_64.rpm --force --nodeps
注:如果运行失败,可以在后面加上--force --nodeps进行强制安装
5. 创建 mysql 的数据文件目录以及所属组
mkdir /u01/mysql
mkdir /u01/mysql/logs
chown -R mysql:mysql /u01/mysql
6. 修改配置文件/etc/my.cnf
[mysqld]
server-id=61
port=38960
character-set-server=utf8mb4
default-time_zone='+8:00'
lower_case_table_names=1
max_connections=3000
max_connect_errors=100000
default_authentication_plugin=mysql_native_password
datadir=/u01/mysql/data
socket=/u01/mysql/mysql.sock
log-error=/u01/mysql/logs/mysqld.log
pid-file=/u01/mysql/mysqld.pid
long_query_time=1
slow_query_log = 1
slow_query_log_file=/u01/mysql/logs/slow.log
[client]
port=38960
default-character-set=utf8mb4
socket=/u01/mysql/mysql.sock
[mysql]
no-auto-rehash
default-character-set=utf8mb4
7. 关闭 selinux,确保 getenforce 的值为 Permissive
setenforce 0 关闭 selinux
getenforce 获取getenforce的值
注:输出结果需为:Permissive 否则可以选择手动修改,如下SELINUX=permissive
vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
8. 启动mysql
systemctl start mysqld
9. 查看root密码
如果上一步没有问题,可在 /data/mysql/logs/mysqld.log 文件中查看root密码。
cat /u01/mysql/logs/mysqld.log
10. 进入mysql命令行界面
mysql -uroot -p 运行后输入上一步查看的root密码
11. 修改root账号密码
alter user 'root'@'localhost' identified by 'KnjVPbv0kZ5IJ!*g';
12. 将mysql加入开机自动启动
vi /etc/rc.local
添加:service mysqld start