当前位置:   article > 正文

CentOS8 Yum安装MySQL_yum install mysql-community-server last metadata e

yum install mysql-community-server last metadata expiration check: 0:00:06 a

RPM包安装MySQL

  • CentOS 8:安装光盘直接提供
    • mysql-server:8.0
    • mariadb-server : 10.3.17
  • CentOS 7:安装光盘直接提供 (抛弃了mysql)
    • mariadb-server:5.5 服务器包
    • mariadb 客户端工具包
  • CentOS 6:
    • mysql-server:5.1 服务器包
    • mysql 客户端工具包

CentOS 8 yum安装自带mysql

yum -y install mysql-server
  • 1
  • 安装 mysql-community-server是不行的
[root@C8-194 ~]# yum -y install mysql-community-server
Last metadata expiration check: 0:28:45 ago on Wed 12 May 2021 05:03:54 PM CST.
No match for argument: mysql-community-server
Error: Unable to find a match: mysql-community-server
  • 1
  • 2
  • 3
  • 4
  • 需要安装mysql-server
[root@C8-194 ~]# yum -y install mysql-server
Last metadata expiration check: 0:28:53 ago on Wed 12 May 2021 05:03:54 PM CST.
Dependencies resolved.
===============================================================================================================
 Package                           Arch        Version                                    Repository      Size
===============================================================================================================
Installing:
 mysql-server                      x86_64      8.0.21-1.module_el8.2.0+493+63b41e36       AppStream       22 M
Upgrading:
 audit                             x86_64      3.0-0.17.20191104git1c2f876.el8            BaseOS         254 k
 audit-libs                        x86_64      3.0-0.17.20191104git1c2f876.el8            BaseOS         116 k
 libsemanage                       x86_64      2.9-3.el8                                  BaseOS         165 k
 policycoreutils                   x86_64      2.9-9.el8                                  BaseOS         377 k
Installing dependencies:
 checkpolicy                       x86_64      2.9-1.el8                                  BaseOS         348 k
 libaio                            x86_64      0.3.112-1.el8                              BaseOS          33 k
 policycoreutils-python-utils      noarch      2.9-9.el8                                  BaseOS         251 k
 python3-audit                     x86_64      3.0-0.17.20191104git1c2f876.el8            BaseOS          86 k
 python3-libsemanage               x86_64      2.9-3.el8                                  BaseOS         127 k
 python3-policycoreutils           noarch      2.9-9.el8                                  BaseOS         2.2 M
 python3-setools                   x86_64      4.3.0-2.el8                                BaseOS         626 k
 mecab                             x86_64      0.996-1.module_el8.2.0+493+63b41e36.9      AppStream      393 k
 mysql-errmsg                      x86_64      8.0.21-1.module_el8.2.0+493+63b41e36       AppStream      581 k
 protobuf-lite                     x86_64      3.5.0-13.el8                               AppStream      149 k

Transaction Summary
===============================================================================================================
Install  11 Packages
Upgrade   4 Packages

Total download size: 28 M
Downloading Packages:
(1/15): libaio-0.3.112-1.el8.x86_64.rpm                                        238 kB/s |  33 kB     00:00    
(2/15): policycoreutils-python-utils-2.9-9.el8.noarch.rpm                      1.1 MB/s | 251 kB     00:00    
(3/15): python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm               1.0 MB/s |  86 kB     00:00    
(4/15): python3-libsemanage-2.9-3.el8.x86_64.rpm                               3.2 MB/s | 127 kB     00:00    
(5/15): checkpolicy-2.9-1.el8.x86_64.rpm                                       1.3 MB/s | 348 kB     00:00    
(6/15): python3-setools-4.3.0-2.el8.x86_64.rpm                                 4.6 MB/s | 626 kB     00:00    
(7/15): mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm           2.0 MB/s | 581 kB     00:00    
(8/15): mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64.rpm                 892 kB/s | 393 kB     00:00    
(9/15): python3-policycoreutils-2.9-9.el8.noarch.rpm                           4.1 MB/s | 2.2 MB     00:00    
(10/15): protobuf-lite-3.5.0-13.el8.x86_64.rpm                                 2.2 MB/s | 149 kB     00:00    
(11/15): audit-libs-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm                 706 kB/s | 116 kB     00:00    
(12/15): libsemanage-2.9-3.el8.x86_64.rpm                                      2.3 MB/s | 165 kB     00:00    
(13/15): policycoreutils-2.9-9.el8.x86_64.rpm                                  2.2 MB/s | 377 kB     00:00    
(14/15): audit-3.0-0.17.20191104git1c2f876.el8.x86_64.rpm                      289 kB/s | 254 kB     00:00    
(15/15): mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64.rpm          7.7 MB/s |  22 MB     00:02    
---------------------------------------------------------------------------------------------------------------
Total                                                                          7.8 MB/s |  28 MB     00:03     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                       1/1 
  Running scriptlet: audit-libs-3.0-0.17.20191104git1c2f876.el8.x86_64                                     1/1 
  Upgrading        : audit-libs-3.0-0.17.20191104git1c2f876.el8.x86_64                                    1/19 
  Upgrading        : libsemanage-2.9-3.el8.x86_64                                                         2/19 
  Installing       : python3-libsemanage-2.9-3.el8.x86_64                                                 3/19 
  Upgrading        : policycoreutils-2.9-9.el8.x86_64                                                     4/19 
  Running scriptlet: policycoreutils-2.9-9.el8.x86_64                                                     4/19 
  Installing       : python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                 5/19 
  Installing       : protobuf-lite-3.5.0-13.el8.x86_64                                                    6/19 
  Installing       : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                             7/19 
  Installing       : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64                                   8/19 
  Running scriptlet: mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64                                   8/19 
  Installing       : python3-setools-4.3.0-2.el8.x86_64                                                   9/19 
  Installing       : libaio-0.3.112-1.el8.x86_64                                                         10/19 
  Installing       : checkpolicy-2.9-1.el8.x86_64                                                        11/19 
  Installing       : python3-policycoreutils-2.9-9.el8.noarch                                            12/19 
  Installing       : policycoreutils-python-utils-2.9-9.el8.noarch                                       13/19 
  Running scriptlet: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                            14/19 
  Installing       : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                            14/19 
  Running scriptlet: mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                            14/19 
ValueError: File context for /var/log/mysql(/.*)? already defined

  Upgrading        : audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                        15/19 
  Running scriptlet: audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                        15/19 
  Running scriptlet: policycoreutils-2.9-3.el8.x86_64                                                    16/19 
  Cleanup          : policycoreutils-2.9-3.el8.x86_64                                                    16/19 
  Running scriptlet: audit-3.0-0.10.20180831git0047a6c.el8.x86_64                                        17/19 
  Cleanup          : audit-3.0-0.10.20180831git0047a6c.el8.x86_64                                        17/19 
  Running scriptlet: audit-3.0-0.10.20180831git0047a6c.el8.x86_64                                        17/19 
  Cleanup          : libsemanage-2.9-1.el8.x86_64                                                        18/19 
  Cleanup          : audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64                                   19/19 
  Running scriptlet: audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64                                   19/19 
  Verifying        : checkpolicy-2.9-1.el8.x86_64                                                         1/19 
  Verifying        : libaio-0.3.112-1.el8.x86_64                                                          2/19 
  Verifying        : policycoreutils-python-utils-2.9-9.el8.noarch                                        3/19 
  Verifying        : python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                 4/19 
  Verifying        : python3-libsemanage-2.9-3.el8.x86_64                                                 5/19 
  Verifying        : python3-policycoreutils-2.9-9.el8.noarch                                             6/19 
  Verifying        : python3-setools-4.3.0-2.el8.x86_64                                                   7/19 
  Verifying        : mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64                                   8/19 
  Verifying        : mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                             9/19 
  Verifying        : mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                            10/19 
  Verifying        : protobuf-lite-3.5.0-13.el8.x86_64                                                   11/19 
  Verifying        : audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                        12/19 
  Verifying        : audit-3.0-0.10.20180831git0047a6c.el8.x86_64                                        13/19 
  Verifying        : audit-libs-3.0-0.17.20191104git1c2f876.el8.x86_64                                   14/19 
  Verifying        : audit-libs-3.0-0.10.20180831git0047a6c.el8.x86_64                                   15/19 
  Verifying        : libsemanage-2.9-3.el8.x86_64                                                        16/19 
  Verifying        : libsemanage-2.9-1.el8.x86_64                                                        17/19 
  Verifying        : policycoreutils-2.9-9.el8.x86_64                                                    18/19 
  Verifying        : policycoreutils-2.9-3.el8.x86_64                                                    19/19 

Upgraded:
  audit-3.0-0.17.20191104git1c2f876.el8.x86_64        audit-libs-3.0-0.17.20191104git1c2f876.el8.x86_64       
  libsemanage-2.9-3.el8.x86_64                        policycoreutils-2.9-9.el8.x86_64                        

Installed:
  mysql-server-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                                                     
  checkpolicy-2.9-1.el8.x86_64                                                                                 
  libaio-0.3.112-1.el8.x86_64                                                                                  
  policycoreutils-python-utils-2.9-9.el8.noarch                                                                
  python3-audit-3.0-0.17.20191104git1c2f876.el8.x86_64                                                         
  python3-libsemanage-2.9-3.el8.x86_64                                                                         
  python3-policycoreutils-2.9-9.el8.noarch                                                                     
  python3-setools-4.3.0-2.el8.x86_64                                                                           
  mecab-0.996-1.module_el8.2.0+493+63b41e36.9.x86_64                                                           
  mysql-errmsg-8.0.21-1.module_el8.2.0+493+63b41e36.x86_64                                                     
  protobuf-lite-3.5.0-13.el8.x86_64                                                                            

Complete!
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124

启动mysql服务并设置为开机启动

[root@C8-194 ~]# systemctl enable --now mysqld
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.
[root@C8-194 ~]# systemctl status mysqld
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-05-12 17:36:06 CST; 48s ago
  Process: 2879 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 2753 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 2728 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 2835 (mysqld)
   Status: "Server is operational"
    Tasks: 39 (limit: 11353)
   Memory: 432.9M
   CGroup: /system.slice/mysqld.service
           └─2835 /usr/libexec/mysqld --basedir=/usr

May 12 17:36:00 C8-194 systemd[1]: Starting MySQL 8.0 database server...
May 12 17:36:00 C8-194 mysql-prepare-db-dir[2753]: Initializing MySQL database
May 12 17:36:06 C8-194 systemd[1]: Started MySQL 8.0 database server.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

查看端口是否已打开

[root@C8-194 ~]# ss -ntl | grep 3306
LISTEN   0         70                        *:33060                  *:*       
LISTEN   0         128                       *:3306                   *:* 
[root@C8-194 ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.21 Source distribution

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

查看数据库状态

mysql> status
  • 1
mysql> status
--------------
mysql  Ver 8.0.21 for Linux on x86_64 (Source distribution)

Connection id:		8
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.21 Source distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb4
Db     characterset:	utf8mb4
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
UNIX socket:		/var/lib/mysql/mysql.sock
Binary data as:		Hexadecimal
Uptime:			8 min 28 sec

Threads: 2  Questions: 6  Slow queries: 0  Opens: 137  Flush tables: 3  Open tables: 55  Queries per second avg: 0.011
--------------
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24

查看默认数据库

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

跑一遍初始化脚本

  • 重置了密码
  • 仅用了匿名用户
  • 删除了默认库
[root@C8-194 ~]# mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 

Invalid option provided.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 

Invalid option provided.

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Please set the password for root here.

New password: 

Re-enter new password: 

Estimated strength of the password: 25 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 ... Failed! Error: Your password does not satisfy the current policy requirements

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 

New password: 

Re-enter new password: 

Estimated strength of the password: 50 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done! 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101

使用更改过的密码登录

mysql -uroot -p'aaaaaaaa'
  • 1

[root@C8-194 ~]# mysql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@C8-194 ~]# mysql -uroot -p aaaaaaaa
Enter password: 
ERROR 1049 (42000): Unknown database 'aaaaaaaa'
[root@C8-194 ~]# mysql -uroot -p'aaaaaaaa'
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 13
Server version: 8.0.21 Source distribution

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> 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

再次查看自带数据库内容

  • 剩下的都是系统数据库了
mysql> show;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/301286
推荐阅读
相关标签
  

闽ICP备14008679号