1.yum在线安装
(1)换源,用CentOS-8.repo,替换/etc/yum.repo.d/redhat.repo文件
1. yum clean all #清理yum缓存,使设置生效
2. yum makecache #将服务器上的软件包信息缓存到本地,提高搜索安装软件的速度
3. yum repolist #显示所有仓库
(2)创建文件夹/soft用来存放安装源cd /soft/
1. wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2. yum install -y mysql157-community-release-el7-10.noarch.rpm
3. yum -y install mysql-community-server
(3)登录修改密码
mysql -u root -p 登录,输入之前记录的随机密码
ALTER USER 'root'@‘localhost’IDENTIFIED BY 'root'
如果报错,说明密码太短或者太简单,没有认证成功
set global validate_password_policy=0;
set global validate_password_length=1;
再进行密码修改,就可以了。
2.rpm离线安装
解压查看:tar xf mysql-5.7.14-1.el7.x86_64.rpm-bundle.tar
1. mysql-community-client 客户端
2. mysql-community-devel 开发库
3. mysql-community-common 服务端和客户端的公共文件
4. mysql-community-embedded 嵌入式
5. mysql-community-serve 服务端
6. mysql-community-test 测试组件
7. mysql-community-libs 共享库
8. mysql-community-libs-compat MySQL之前版本的共享兼容库
(1)安装:
首先限制mariadb相关软件包,否则安装不会成功。
yum remove mariadb-libs
安装顺序:
a.rpm -ivh mysql-community-common-5.7.30-1.el7.x86_64.rpm
b.rpm -ivh mysql-community-libs-5.7.30-1.el7.x86_64.rpm
c.rpm -ivh mysql-community-client-5.7.30-1.el7.x86_64.rpm
d.rpm -ivh mysql-community-server-5.7.30-1.el7.x86_64.rpm(可能会因为缺少依赖包报错)
1. 启动数据库
2. root@localhost soft] systemctl start mysqld
3. [root@localhost soft] systemctl enable mysqld
=============检查服务有无开启
4. [root@localhost soft] systemctl is-active mysqld.service
active #开启
5. [root@localhost soft] systemctl is-enable mysqld
Unknown operation is-enable.
- 查找初始随机密码grep ‘temporary password’ /var/log/mysqld.log
- 登录修改密码
如果找不到随机密码可以用:
默认有个随机密码:
more /var/log/mysql.log
3.二进制安装
1.下载安装包
2.新建用户
groupadd -r -g 306 mysql
useradd -g 306 -r -u 306 mysql
3.安装mysql并初始化,用xftp将文件传输到/usr/local/下
1. [root@localhost ~] cd /usr/local/
2. [root@localhost local] tar xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
3. [root@localhost local] ln -sv mysql-5.7.14-linux-glibc2.5-x86_64 mysql #创建软连接,方便之后操作
"mysql" -> "mysql-5.7.14-linux-glibc2.5-x86_64"
4. [root@localhost local] chown -R mysql.mysql mysql/*
1
初始化:
初始化命令:
mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
4.为mysql提供配置文件:
1. [root@localhost local] cd /usr/local/mysql
2. [root@localhost mysql] \cp support-files/my-default.cnf /etc/my.cnf
3. [root@localhost mysql] vim /etc/my.cnf
添加如下行指定mysql数据文件的存放位置:
[root@localhost mysql] datadir = /usr/local/mysql/data
5.为mysql提供脚本:
1.[root@localhost mysql] cp support-files/mysql.server /etc/rc.d/init.d/mysqld
2.[root@localhost mysql] chmod +x /etc/rc.d/init.d/mysqld
6.启动mysql服务:
chkconfig --add mysqld --添加为系统服务
chkconfig mysqld on --开机自启动
systemctl start mysqld
7.将mysql的bin目录加入path环境变量,
cd /etc/profile.d/
vim mysql.sh
• 添加如下内容
export PATH=$PATH:/usr/local/mysql/bin
之后
source mysql.sh
安装完成。