title: MySQL安装
category: MySQL
tag: mysql
Linux(CentOS 7)
下载MySQL8版本
MySQL官方网址:MySQL
前期验证
检查是否安装MySQL
rpm -qa|grep mysql
检查是否存在mariadb
rpm -qa|grep mariadb
检查是否开放防火墙
systemctl status firewalld 查看firewall服务状态
service firewalld start 开启 firewalld.service服务
service firewalld restart 重启 firewalld.service服务
service firewalld stop 关闭 firewalld.service服务
firewall-cmd --list-all 查看全部信息
firewall-cmd --list-ports 只看端口信息
firewall-cmd --zone=public --add-port=3306/tcp --permanent 开端口命令
systemctl restart firewalld.service 重启防火墙
--zone 作用域
--add-port=80/tcp 添加端口,格式为:端口/通讯协议
--permanent 永久生效,没有此参数重启后失效
安装MySQL
- 在官网中下载MySQL rpm版 并通过xftp上传到Linux中
解压文件
tar -xvf mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
1.安装mysql-community-common-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm
2.安装mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm
3.安装mysql-community-libs-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm
4.安装mysql-community-client-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm
5.安装mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm
6.安装mysql-community-server-8.0.28-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm
初始化数据库
mysqld -- initialize --console
修改安装目录所属组
chown -R mysql:mysql /var/lib/mysql/
启动服务
systemctl start mysqld
查询临时密码
cat /var/log/mysqld.log|grep localhost
登录MySQL
mysql -uroot -p
修改临时密码
alter user 'root'@'localhost' identified by 'Zhou1252161!';
远程登录授权
use mysql;
select host, user from user;
update user set host='%' where user ='root';
select host, user from user;
flush privileges;
重启MySQL
systemctl restart mysqld