Linux安装MySQL5.7(使用rpm安装)

Linux下安装MySQL5.7(使用rpm安装)

  1. 首先在 /usr/local/目录下新建一个文件夹 mysql
  2. 切换到mysql目录下

(1)下载

**//下载安装包**
[root@localhost mysql]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar

//**解压在mysql文件夹内**
[root@localhost mysql]# tar -xf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar 

//**安装依赖包**
[root@localhost mysql]# yum -y install make gcc-c++ cmake bison-devel ncurses-devel libaio-devel net-tools

**由于Centos7开始自带的数据库是mariadb,所以需要卸载系统中的mariadb组件,才能安装mysql的组件**
[root@localhost mysql]# rpm -qa | grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost mysql]# yum -y remove mariadb-libs                  //卸载

(2)安装

[root@localhost mysql]# rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm 
警告:mysql-community-common-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-common-5.7.22-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm 
警告:mysql-community-libs-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-5.7.22-1.el7################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm 
警告:mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-libs-compat-5.7.2################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm 
警告:mysql-community-client-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-client-5.7.22-1.e################################# [100%]
[root@localhost mysql]# rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm 
警告:mysql-community-server-5.7.22-1.el7.x86_64.rpm: 头V3 DSA/SHA1 Signature, 密钥 ID 5072e1f5: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql-community-server-5.7.22-1.e################################# [100%]

(3)启动

[root@localhost mysql]# systemctl start mysqld
[root@localhost mysql]# systemctl enable mysqld
[root@localhost mysql]# systemctl status mysqld

(4)查找密码并登录

[root@localhost mysql]# grep "password" /var/log/mysqld.log    // 前往日志文件查找临时密码
2022-01-17T14:15:30.044799Z 1 [Note] A temporary password is generated for root@localhost: VihNdp7u+ff;
//密码用引号包住,因为有特殊符号
[root@localhost mysql]# mysql -uroot -p"VihNdp7u+ff;"

(5)重新设置密码格式

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> set password for root@localhost=password('root');         //设置密码
Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> exit           //退出
Bye


(6)用新密码重新登录

[root@localhost mysql]# mysql -uroot -proot         
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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> 

至此MySQL就安装完成了

你可能感兴趣的:(Linux,mysql,linux,mariadb)