一、资源地址
二、安装前准备,卸载自带的 mariadb,安装依赖环境
列出已安装的 mariadb
[root@mysql ~]# rpm -qa | grep mariadb mariadb-libs-5.5.60-1.el7_5.x86_64 方法一:rpm -e --nodeps 卸载 mariadb [root@mysql ~]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64 方法二:yum -y remove 卸载 mariadb [root@mysql ~]# yum -y remove mariadb-libs-5.5.60-1.el7_5.x86_64
如果有多余的残留目录删除它,没有则跳过
[root@mysql ~]# find / -name mysql -print 如下: [root@mysql ~]# rm -rf /var/lib/mysql [root@mysql ~]# rm -rf /var/lib/mysql/mysql [root@mysql ~]# rm -rf /usr/bin/mysql [root@mysql ~]# rm -rf /usr/lib64/mysql
安装基础软件。
[root@mysql ~]# yum -y install wget (如果你不用ftp或者lrzsz上传) [root@mysql ~]# yum -y install lrzsz (简单好用的上传下载软件) [root@mysql ~]# yum -y install vim
安装依赖软件。
[root@mysql ~]# yum -y install net-tools [root@mysql ~]# yum -y install openssl openssl-devel [root@mysql ~]# yum -y install libaio libaio-devel [root@mysql ~]# yum -y install perl perl-devel [root@mysql ~]# yum -y install perl-JSON.noarch [root@mysql ~]# yum -y install autoconf
三、查看、关闭 firewall 防火墙
[root@mysql home]# firewall-cmd --state [root@mysql home]# systemctl stop firewalld.service [root@mysql home]# systemctl disable firewalld.service
四、关闭selinux,进入到/etc/selinux/config文件,将SELINUX=enforcing 改为SELINUX=disabled
[root@mysql home]# vi /etc/selinux/config
五、重启 CentOS…
[root@mysql home]# reboot
六、上传mysql的tar包,解压tar包
[root@mysql ~]# cd /home [root@mysql home]# tar -xvf mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar [root@mysql mysql]# ls -lShr
七、开始安装mysql
PS:注意安装顺序 common -> -client-plugins -> libs -> client -> server [root@mysql mysql]# rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm [root@mysql mysql]# rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.rpm [root@mysql mysql]# rpm -ivh mysql-community-client-8.0.17-1.el7.x86_64.rpm [root@mysql mysql]# rpm -ivh mysql-community-server-8.0.17-1.el7.x86_64.rpm [root@mysql mysql]# rpm -ivh mysql-community-libs-compat-8.0.17-1.el7.x86_64.rpm(可选) [root@mysql mysql]# rpm -ivh mysql-community-devel-8.0.17-1.el7.x86_64.rpm(可选) [root@mysql mysql]# rpm -ivh mysql-community-embedded-compat-8.0.17-1.el7.x86_64.rpm(可选) [root@mysql mysql]# rpm -ivh mysql-community-test-8.0.17-1.el7.x86_64.rpm(可选) [root@mysql mysql]# rpm -qa | grep mysql
八、初始化数据库,目录授权,启动mysql服务 [注意操作顺序]
[root@gnome mysql]# mysqld --initialize --console --lower_case_table_names=1 (初始化,并设置不区分大小写) [root@gnome mysql]# chown -R mysql:mysql /var/lib/mysql/ [root@gnome mysql]# systemctl start mysqld
九、查看是否启动成功,active (running)
十、查看初始化后的临时密码
[root@gnome mysql]# grep 'temporary password' /var/log/mysqld.log 或者 [root@gnome mysql]# cat /var/log/mysqld.log | grep 'temporary password'
十一、登录mysql
[root@mysql home]# mysql -u root -p Enter password: 直接粘贴初始密码 ,回车确认
十二、修改初始密码,授权远程登录
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'HomeTest$2019'; (修改 “HomeTest$2019” 为你自己的密码) mysql> use mysql; (切换到mysql库) mysql> update user set host = "%" where user='root'; (授权远程登录) mysql> flush privileges; (刷新) mysql> quit; (退出登录)
十四、配置 后重启
vim /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysql]
local-infile=1
[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 the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_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
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
lower-case-table-names=1
local-infile=1