https://downloads.mysql.com/archives/community/
将下载的安装上传到CentOS7虚拟机系统中某一目录下。
当然也可以登录进入CentOS7虚拟机系统内通过wget下载(不过不建议采用种方式,主要是安装包有些大)
[root@localhost ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]#
[root@localhost ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
[root@localhost ~]#
[root@localhost ~]# rpm -qa | grep mariadb
[root@localhost ~]#
安装我们下载好的Mysql5.7
进入我们下载Mysql5.7安装包所在目录
[root@localhost ~]#
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
然后解压
[root@localhost ~]# ls
anaconda-ks.cfg mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
[root@localhost ~]# tar -xvf mysql-5.7.21-1.el7.x86_64.rpm-bundle.tar
依次执行下面安装命令
rpm -ivh mysql-community-common-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.21-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-compat-5.7.21-1.el7.x86_64.rpm
以安全模式初始化mysql
mysqld --initialize --user=mysql
查看 初始化密码
[root@localhost ~]# grep "password" /var/log/mysqld.log
2020-05-26T04:08:07.475037Z 1 [Note] A temporary password is generated for root@localhost: y&F6MP<hhlSf
启动Mysql并检查其服务状态
[root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2020-05-26 12:10:02 CST; 4s ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 2434 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 2417 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 2437 (mysqld)
CGroup: /system.slice/mysqld.service
└─2437 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
5月 26 12:10:02 localhost.localdomain systemd[1]: Starting MySQL Server...
5月 26 12:10:02 localhost.localdomain systemd[1]: Started MySQL Server.
设置 mysql 服务自启动
[root@localhost ~]# systemctl enable mysqld
// 设置完成后,通过下面代码查看是否设置成功
[root@localhost ~]# systemctl list-unit-files --type=service | grep mysqld
mysqld.service enabled
mysqld@.service disabled
修改初始化密码
查看初始化密码
[root@localhost ~]# grep "password" /var/log/mysqld.log
2020-05-26T04:08:07.475037Z 1 [Note] A temporary password is generated for root@localhost: y&F6MP<hhlSf
使用初始化密码登入mysql
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.21
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> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
修改初始化密码
mysql> alter user 'root'@'localhost' identified by 'root';
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Mysql安装完成
使用修改后的密码,正式登录使用Mysql
[root@localhost ~]# 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 4
Server version: 5.7.21 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql>
修改 root 登录限制为允许开放所有登录方式(远程登录)
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> select user,host from user;
+---------------+-----------+
| user | host |
+---------------+-----------+
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+---------------+-----------+
3 rows in set (0.00 sec)
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>
远程客户端登录测试