Linux

centos7 离线安装 mysql

2020-12-29  本文已影响0人  lconcise

1. 下载 mysql 离线包

下载mysql 离线包:mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar

官网地址:https://dev.mysql.com/downloads/mysql/

image.png image.png

2. 上传解压

我的上传解压路径:/home/mysql

 tar -xvf mysql-5.7.32-1.el7.x86_64.rpm-bundle.tar
image.png

3. 查询并卸载系统自带的Mariadb

rpm -qa | grep mariadb
rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

4. 查询并卸载系统老旧版本的Mysql

rpm -qa | grep mysql
rpm -e --nodeps 文件名

5. 解压包安装

  rpm -ivh mysql-community-common-5.7.32-1.el7.x86_64.rpm
  rpm -ivh mysql-community-libs-5.7.32-1.el7.x86_64.rpm
  rpm -ivh mysql-community-devel-5.7.32-1.el7.x86_64.rpm
  rpm -ivh mysql-community-libs-compat-5.7.32-1.el7.x86_64.rpm
  rpm -ivh mysql-community-client-5.7.32-1.el7.x86_64.rpm
  rpm -ivh mysql-community-server-5.7.32-1.el7.x86_64.rpm

6. 启动mysql 服务

查看mysql服务是否启动(默认没有启动,需要手动启动)
service mysqld status

启动服务:
systemctl start mysqld

image.png

7. 查看生产随机密码

MySQL5.7会在安装后为root用户生成一个随机密码,而不是像以往版本的空密码。 可以安全模式修改root登录密码或者用随机密码登录修改密码。下面用随机密码方式
MySQL为root用户生成的随机密码通过mysqld.log文件可以查找到:

 grep 'temporary password' /var/log/mysqld.log
image.png

8. 修改用户密码

mysql> set password = password("Szfore_68638");

或者方式二:

alter user 'root'@'localhost' identified by '123456';

如果出现以下错误:

 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

解决方案:

 set global validate_password_policy=0;
 set global validate_password_length=1;

9. 如果上面的方式不能修改可以使用下面安全模式修改root

编辑 vim /etc/my.cnf 添加

skip-grant-tables

systemctl restart mysqld.service

10. 开发远程访问权限

mysql> use mysql;
Database changed
mysql> grant all privileges  on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

grant all privileges on . to root@'%' identified by "password"; password 需要修改为自己的密码

11. 防火墙配置3306端口允许外部访问

查询防火墙状态 systemctl status firewalld.service


image.png

开启防火墙mysql 3306端口的外部访问:
firewall-cmd --zone=public --add-port=3306/tcp –permanent
firewall-cmd –reload

或者直接关闭防火墙:

systemctl stop firewalld.service

参考文档:
https://blog.csdn.net/weixin_41238134/article/details/99707670
https://www.cnblogs.com/weifeng1463/p/7941625.html
https://blog.csdn.net/ai_64/article/details/100557530

上一篇下一篇

猜你喜欢

热点阅读