[root@MySQL ~]# uname -r
3.10.0-862.el7.x86_64
[root@MySQL ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
登录mysql官网https://dev.mysql.com,单击“DOWNLOADS”
点击“MySQL Community (GPL) Downloads »”
选择“MySQL Yum Repository”
选择“Red Hat Enterprise Linux 7 / Oracle Linux 7 (Architecture Independent), RPM Package mysql80-community-release-el7-3.noarch.rpm)”,点击“Download”
点击“No thanks, just start my download.”
完整下载链接:https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
[root@mysql_yum ~]# mkdir /opt/mysql_yum
[root@mysql_yum ~]# cd /opt/mysql_yum
[root@mysql_yum mysql_yum]# rz -E
rz waiting to receive.
[root@mysql_yum mysql_yum]# ls
mysql80-community-release-el7-3.noarch.rpm
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm
warning: mysql80-community-release-el7-3.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# rpm -ql mysql80-community-release
/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
/etc/yum.repos.d/mysql-community-source.repo
/etc/yum.repos.d/mysql-community.repo
[root@mysql_yum mysql_yum]#
默认情况下,是安装8.0版本的,它的enabled=1,我们这里安装的是5.7,故将5.7的enabled改为1,8.0的改为0
[root@mysql_yum mysql_yum]# vim /etc/yum.repos.d/mysql-community.repo
# Enable to use MySQL 5.5
[mysql55-community]
name=MySQL 5.5 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
# Enable to use MySQL 5.7
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1 //将0改为1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
enabled=0 //将1改为0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
#内容过长,省略部分内容
Metadata Cache Created
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: mirror.bit.edu.cn
#内容过长,省略部分内容
Installing:
mysql-community-libs x86_64 5.7.31-1.el7 mysql57-community 2.3 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.31-1.el7 mysql57-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.31-1.el7 mysql57-community 173 M
Installing for dependencies:
mysql-community-client x86_64 5.7.31-1.el7 mysql57-community 25 M
mysql-community-common x86_64 5.7.31-1.el7 mysql57-community 311 k
net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
Updating for dependencies:
postfix x86_64 2:2.10.1-9.el7 base 2.4 M
Transaction Summary
========================================================================================================================================
Install 3 Packages (+3 Dependent packages)
Upgrade ( 1 Dependent package)
Total download size: 205 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.31-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.31-1.el7.x86_64.rpm is not installed
#内容过长,省略部分内容
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
Installing : mysql-community-common-5.7.31-1.el7.x86_64 1/9
Installing : mysql-community-libs-5.7.31-1.el7.x86_64 2/9
Installing : mysql-community-libs-compat-5.7.31-1.el7.x86_64 3/9
Installing : mysql-community-client-5.7.31-1.el7.x86_64 4/9
Installing : net-tools-2.0-0.25.20131004git.el7.x86_64 5/9
Installing : mysql-community-server-5.7.31-1.el7.x86_64 [############################################################################## Installing : mysql-community-server-5.7.31-1.el7.x86_64 6/9
Updating : 2:postfix-2.10.1-9.el7.x86_64 7/9
Cleanup : 2:postfix-2.10.1-6.el7.x86_64 8/9
Erasing : 1:mariadb-libs-5.5.56-2.el7.x86_64 9/9
Verifying : mysql-community-libs-compat-5.7.31-1.el7.x86_64 1/9
Verifying : mysql-community-common-5.7.31-1.el7.x86_64 2/9
Verifying : 2:postfix-2.10.1-9.el7.x86_64 3/9
Verifying : mysql-community-server-5.7.31-1.el7.x86_64 4/9
Verifying : net-tools-2.0-0.25.20131004git.el7.x86_64 5/9
Verifying : mysql-community-client-5.7.31-1.el7.x86_64 6/9
Verifying : mysql-community-libs-5.7.31-1.el7.x86_64 7/9
Verifying : 1:mariadb-libs-5.5.56-2.el7.x86_64 8/9
Verifying : 2:postfix-2.10.1-6.el7.x86_64 9/9
Installed:
mysql-community-libs.x86_64 0:5.7.31-1.el7 mysql-community-libs-compat.x86_64 0:5.7.31-1.el7
mysql-community-server.x86_64 0:5.7.31-1.el7
Dependency Installed:
mysql-community-client.x86_64 0:5.7.31-1.el7 mysql-community-common.x86_64 0:5.7.31-1.el7 net-tools.x86_64 0:2.0-0.25.20131004git.el7
Dependency Updated:
postfix.x86_64 2:2.10.1-9.el7
Replaced:
mariadb-libs.x86_64 1:5.5.56-2.el7
Complete!
[root@mysql_yum mysql_yum]#
离线安装需要下载这些安装包
Installing:
mysql-community-libs x86_64 5.7.31-1.el7 mysql57-community 2.3 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-libs-compat x86_64 5.7.31-1.el7 mysql57-community 1.2 M
replacing mariadb-libs.x86_64 1:5.5.56-2.el7
mysql-community-server x86_64 5.7.31-1.el7 mysql57-community 173 M
Installing for dependencies:
mysql-community-client x86_64 5.7.31-1.el7 mysql57-community 25 M
mysql-community-common x86_64 5.7.31-1.el7 mysql57-community 311 k
net-tools x86_64 2.0-0.25.20131004git.el7 base 306 k
Updating for dependencies:
postfix x86_64 2:2.10.1-9.el7 base 2.4 M
但是安装时要按顺序
Installing : mysql-community-common-5.7.31-1.el7.x86_64
Installing : mysql-community-libs-5.7.31-1.el7.x86_64
Installing : mysql-community-libs-compat-5.7.31-1.el7.x86_64
Installing : mysql-community-client-5.7.31-1.el7.x86_64
Installing : net-tools-2.0-0.25.20131004git.el7.x86_64
Installing : mysql-community-server-5.7.31-1.el7.x86_64
[root@mysql_yum mysql_yum]# systemctl start mysqld
[root@mysql_yum mysql_yum]# ss -antlp | grep mysql
LISTEN 0 80 :::3306 :::* users:(("mysqld",pid=2282,fd=21))
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# grep "password" /var/log/mysqld.log
2020-08-13T06:18:57.792715Z 1 [Note] A temporary password is generated for root@localhost: Z+:!ti>1qoa9
[root@mysql_yum mysql_yum]#
[root@mysql_yum mysql_yum]# mysql -u root -p
Enter password: //初始密码为Z+:!ti>1qoa9
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31
Copyright (c) 2000, 2020, 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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
#错误1820 (HY000):在执行此语句之前,您必须使用ALTER USER语句重置您的密码。
mysql> alter user root@localhost identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
#错误1819 (HY000):您的密码不符合当前的策略要求
#MySQL的密码规则:8位,必须包含字母大小写、数字、特殊字符
mysql> alter user root@localhost identified by 'Pwd@1234';
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@mysql_yum mysql_yum]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.31 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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> show databases; #查看现有数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database mytest; #创建数据库
Query OK, 1 row affected (0.00 sec)
mysql> use mytest; #切换数据库
Database changed
mysql> create table test (id int primary key, name varchar(20)); #创建表
Query OK, 0 rows affected (0.01 sec)
mysql> show tables; #查看表
+------------------+
| Tables_in_mytest |
+------------------+
| test |
+------------------+
1 row in set (0.00 sec)
mysql> desc test; #查看表结构
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | NO | PRI | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.13 sec)
mysql> insert into test values (1,"zhang"),(2,"li"),(3,"zhao"); #插入数据
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from test; #查看表内容
+----+-------+
| id | name |
+----+-------+
| 1 | zhang |
| 2 | li |
| 3 | zhao |
+----+-------+
3 rows in set (0.00 sec)
mysql> select version(); #查看mysql数据库的版本
+-----------+
| version() |
+-----------+
| 5.7.31 |
+-----------+
1 row in set (0.00 sec)
mysql>
这只是我的一些浅薄的见解,望多指教!