centos7 yum安装 mysql5.7

1、下载安装包
http://dev.mysql.com/downloads/mysql/#downloads


下载 mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar

 

2、卸载系统自带的Mariadb

查看mariadb数据库:

rpm -qa | grep mariadb

 

卸载mariadb数据库:

rpm -e --nodeps mariadb-xxx

3、卸载已安装的mysql

查看 mysql 数据库:

rpm -qa | grep mysql

卸载 mysql 数据库:

rpm -e --nodeps mysql-xxxx

4、tar文件上传到opt并解压

[root@localhost opt]# ls
mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar
#新建mysql5.7文件夹,存放解压后的rpm包
[root@localhost opt]# mkdir mysql5.7
[root@localhost opt]# tar -xvf mysql-5.7.25-1.el7.x86_64.rpm-bundle.tar -C mysql5.7/
mysql-community-libs-5.7.25-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-5.7.25-1.el7.x86_64.rpm
mysql-community-client-5.7.25-1.el7.x86_64.rpm
mysql-community-server-5.7.25-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.25-1.el7.x86_64.rpm
mysql-community-test-5.7.25-1.el7.x86_64.rpm
mysql-community-devel-5.7.25-1.el7.x86_64.rpm
mysql-community-common-5.7.25-1.el7.x86_64.rpm
[root@localhost opt]#

5、安装,使用rpm -ivh 依次安装common、libs 、client、server、devel(存在依赖关系的,所以在安装时有顺序)

[root@localhost opt]# cd mysql5.7/
[root@localhost mysql5.7]# rpm -ivh mysql-community-common-5.7.25-1.el7.x86_64.rpm
[root@localhost mysql5.7]# rpm -ivh mysql-community-libs-5.7.25-1.el7.x86_64.rpm
[root@localhost mysql5.7]# rpm -ivh mysql-community-client-5.7.25-1.el7.x86_64.rpm
[root@localhost mysql5.7]# rpm -ivh mysql-community-server-5.7.25-1.el7.x86_64.rpm
[root@localhost mysql5.7]# rpm -ivh mysql-community-devel-5.7.25-1.el7.x86_64.rpm

6、修改/etc/my.cnf

后面新增validate_password=off 

注:validate_password=off 是关闭密码验证插件,如果不加,root密码长度复杂度要验证,不符合验证报1819错误

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

1819错误也可通过下面代码解决:

set global validate_password_policy=LOW;
set global validate_password_length=3;

7、重启mysql服务

systemctl restart mysqld.service

8、查看临时密码并登录修改root密码

[root@localhost mysql5.7]# cat /var/log/mysqld.log | grep 'temporary password'
2019-03-04T03:57:19.584151Z 1 [Note] A temporary password is generated for root@localhost: 6+wC=VqT2vRa

使用临时密码登录mysql 

[root@localhost mysql5.7]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.25

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select version();
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

mysql登陆后要修改root密码,如果不修改密码,会提示1820错误

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> ALTER USER USER() IDENTIFIED BY 'root';
Query OK, 0 rows affected (0.01 sec)

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

 

9、mysql的远程访问

mysql> grant all privileges on *.* to root@'%' identified by 'root';
Query OK, 0 rows affected, 1 warning (0.01 sec)

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

10、开放3306端口

[root@localhost /]# firewall-cmd --zone=public --add-port=3306/tcp --permanent
success
[root@localhost /]# firewall-cmd --reload
success

11、开机启动

systemctl enable mysqld

mysql5.7安装完成

12、(可选)设置安全选项:

[root@localhost /]# mysql_secure_installation

运行mysql_secure_installation会执行几个设置:
--为root用户设置密码
--删除匿名账号
--取消root用户远程登录
--删除test库和对test库的访问权限
--刷新授权表使修改生效

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章