数据库运维
记录DBA学习成长历程

Centos7安装MySQL8.0.19

文章目录

检查是否有mariadb,并删除

[root@test ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@test ~]# rpm -e mariadb-libs-5.5.56-2.el7.x86_64 --nodeps
[root@test ~]#

创建mysql目录,上传安装包,解压

[root@test ~]# cd /usr/local/
[root@test local]# mkdir mysql
[root@test local]# cd mysql/
[root@test mysql]# ll
total 747372
-rw-r--r-- 1 root root 765306880 Mar 15 11:13 mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
[root@test mysql]# tar -xvf mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar 
mysql-community-client-8.0.19-1.el7.x86_64.rpm
mysql-community-server-8.0.19-1.el7.x86_64.rpm
mysql-community-test-8.0.19-1.el7.x86_64.rpm
mysql-community-common-8.0.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm
mysql-community-devel-8.0.19-1.el7.x86_64.rpm
mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
mysql-community-libs-8.0.19-1.el7.x86_64.rpm
[root@test mysql]# ll
total 1494740
-rw-r--r-- 1 root root  765306880 Mar 15 11:13 mysql-8.0.19-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  43126424 Dec 10 20:59 mysql-community-client-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    619248 Dec 10 20:59 mysql-community-common-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   7421828 Dec 10 20:59 mysql-community-devel-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  23691824 Dec 10 20:59 mysql-community-embedded-compat-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   4212908 Dec 10 20:59 mysql-community-libs-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   1365572 Dec 10 20:59 mysql-community-libs-compat-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 457272180 Dec 10 21:00 mysql-community-server-8.0.19-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 227581052 Dec 10 21:01 mysql-community-test-8.0.19-1.el7.x86_64.rpm

安装 common

[root@test mysql]# rpm -ivh mysql-community-common-8.0.19-1.el7.x86_64.rpm --nodeps --force
warning: mysql-community-common-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-common-8.0.19-1.e################################# [100%]

安装 libs

[root@test mysql]# rpm -ivh mysql-community-libs-8.0.19-1.el7.x86_64.rpm --nodeps --force
warning: mysql-community-libs-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-libs-8.0.19-1.el7################################# [100%]

安装 client

[root@test mysql]# rpm -ivh mysql-community-client-8.0.19-1.el7.x86_64.rpm --nodeps --force
warning: mysql-community-client-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-client-8.0.19-1.e################################# [100%]

安装 server

[root@test mysql]# rpm -ivh mysql-community-server-8.0.19-1.el7.x86_64.rpm --nodeps --force
warning: mysql-community-server-8.0.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-community-server-8.0.19-1.e################################# [100%]

查看安装情况

[root@test mysql]# rpm -qa | grep mysql
mysql-community-libs-8.0.19-1.el7.x86_64
mysql-community-client-8.0.19-1.el7.x86_64
mysql-community-server-8.0.19-1.el7.x86_64
mysql-community-common-8.0.19-1.el7.x86_64

初始化数据库,启动

[root@test mysql]# mysqld --initialize;
[root@test mysql]# chown mysql:mysql /var/lib/mysql -R;
[root@test mysql]# systemctl start mysqld.service;
[root@test mysql]# systemctl enable mysqld;

查看数据库的密码

[root@test mysql]# cat /var/log/mysqld.log | grep password
2020-03-15T03:23:45.386932Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: #dlMBN(?*7yf

登录数据库

[root@test mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.19

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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.03 sec)

mysql>

重新登录

[root@test mysql]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19 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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

创建用户进行远程访问的授权

mysql> create user 'root'@'%' identified with mysql_native_password by 'root';
Query OK, 0 rows affected (0.02 sec)

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

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

赞(1)
MySQL学习笔记 » Centos7安装MySQL8.0.19