Centos8使用yum安装Mysql8.0数据库

参考官方文档

准备环境

1.选择适用于你系统mysql的rpm安装包
在这里插入图片描述
2.准备好一台安装Centos8的操作系统
3.将下载的mysql80-community-release-el8-1.noarch.rpm上传到Centos8

更新yum

[root@WzcWyt wyt]# yum update

检查是否已安装mysql

# 查看是否按mysql
[root@WzcWyt wyt]# rpm -qa | grep mysql

安装命令将MySQL Yum存储库添加到系统的存储库列表中

[root@WzcWyt wyt]# sudo yum install mysql80-community-release-el8-1.noarch.rpm
Last metadata expiration check: 2:34:59 ago on Wed 21 Apr 2021 10:36:25 AM CST.
Dependencies resolved.
====================================================================================================================================================================
 Package                                             Architecture                     Version                          Repository                              Size
====================================================================================================================================================================
Installing:
 mysql80-community-release                           noarch                           el8-1                            @commandline                            30 k

Transaction Summary
====================================================================================================================================================================
Install  1 Package

Total size: 30 k
Installed size: 29 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                            1/1 
  Installing       : mysql80-community-release-el8-1.noarch                                                                                                     1/1 
  Verifying        : mysql80-community-release-el8-1.noarch                                                                                                     1/1 

Installed:
  mysql80-community-release-el8-1.noarch                                                                                                                            

Complete!

检查是否已成功添加MySQL Yum存储库

[root@WzcWyt wyt]# yum repolist enabled | grep "mysql.*-community.*"
mysql-connectors-community    MySQL Connectors Community
mysql-tools-community         MySQL Tools Community
mysql80-community             MySQL 8.0 Community Server

检查启用和禁用了哪些库

[root@WzcWyt wyt]# yum repolist all | grep mysql
mysql-cluster-8.0-community        MySQL Cluster 8.0 Community          disabled
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - Source disabled
mysql-connectors-community         MySQL Connectors Community           enabled
mysql-connectors-community-source  MySQL Connectors Community - Source  disabled
mysql-tools-community              MySQL Tools Community                enabled
mysql-tools-community-source       MySQL Tools Community - Source       disabled
mysql-tools-preview                MySQL Tools Preview                  disabled
mysql-tools-preview-source         MySQL Tools Preview - Source         disabled
mysql80-community                  MySQL 8.0 Community Server           enabled
mysql80-community-source           MySQL 8.0 Community Server - Source  disabled
[root@WzcWyt wyt]# 

禁用默认的MySQL模块

[root@WzcWyt wyt]# sudo yum module disable mysql
Last metadata expiration check: 3:01:50 ago on Wed 21 Apr 2021 10:36:25 AM CST.
Dependencies resolved.
====================================================================================================================================================================
 Package                                Architecture                          Version                                  Repository                              Size
====================================================================================================================================================================
Disabling modules:
 mysql                                                                                                                                                             

Transaction Summary
====================================================================================================================================================================

Is this ok [y/N]: y
Complete!
[root@WzcWyt wyt]# 

安装Mysql

[root@WzcWyt wyt]# sudo yum install mysql-community-server
Last metadata expiration check: 3:02:50 ago on Wed 21 Apr 2021 10:36:25 AM CST.
Dependencies resolved.
====================================================================================================================================================================
 Package                                              Architecture                 Version                            Repository                               Size
====================================================================================================================================================================
Installing:
 mysql-community-server                               x86_64                       8.0.23-1.el8                       mysql80-community                        53 M
     replacing  mariadb-connector-c-config.noarch 3.1.11-2.el8_3
Installing dependencies:
 mysql-community-client                               x86_64                       8.0.23-1.el8                       mysql80-community                        12 M
 mysql-community-client-plugins                       x86_64                       8.0.23-1.el8                       mysql80-community                       108 k
 mysql-community-common                               x86_64                       8.0.23-1.el8                       mysql80-community                       624 k
 mysql-community-libs                                 x86_64                       8.0.23-1.el8                       mysql80-community                       1.4 M

Transaction Summary
====================================================================================================================================================================
Install  5 Packages

Total download size: 67 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): mysql-community-client-plugins-8.0.23-1.el8.x86_64.rpm                                                                       105 kB/s | 108 kB     00:01    
(2/5): mysql-community-common-8.0.23-1.el8.x86_64.rpm                                                                               328 kB/s | 624 kB     00:01    
(3/5): mysql-community-libs-8.0.23-1.el8.x86_64.rpm                                                                                 948 kB/s | 1.4 MB     00:01    
(4/5): mysql-community-client-8.0.23-1.el8.x86_64.rpm                                                                               3.0 MB/s |  12 MB     00:04    
(5/5): mysql-community-server-8.0.23-1.el8.x86_64.rpm                                                                               5.6 MB/s |  53 MB     00:09    
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                               5.9 MB/s |  67 MB     00:11     
warning: /var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.23-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
MySQL 8.0 Community Server                                                                                                           27 MB/s |  27 kB     00:00    
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                            1/1 
  Installing       : mysql-community-common-8.0.23-1.el8.x86_64                                                                                                 1/6 
  Installing       : mysql-community-client-plugins-8.0.23-1.el8.x86_64                                                                                         2/6 
  Installing       : mysql-community-libs-8.0.23-1.el8.x86_64                                                                                                   3/6 
  Running scriptlet: mysql-community-libs-8.0.23-1.el8.x86_64                                                                                                   3/6 
  Installing       : mysql-community-client-8.0.23-1.el8.x86_64                                                                                                 4/6 
  Running scriptlet: mysql-community-server-8.0.23-1.el8.x86_64                                                                                                 5/6 
  Installing       : mysql-community-server-8.0.23-1.el8.x86_64                                                                                                 5/6 
  Running scriptlet: mysql-community-server-8.0.23-1.el8.x86_64                                                                                                 5/6 
  Obsoleting       : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                           6/6 
  Running scriptlet: mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                           6/6 
  Verifying        : mysql-community-client-8.0.23-1.el8.x86_64                                                                                                 1/6 
  Verifying        : mysql-community-client-plugins-8.0.23-1.el8.x86_64                                                                                         2/6 
  Verifying        : mysql-community-common-8.0.23-1.el8.x86_64                                                                                                 3/6 
  Verifying        : mysql-community-libs-8.0.23-1.el8.x86_64                                                                                                   4/6 
  Verifying        : mysql-community-server-8.0.23-1.el8.x86_64                                                                                                 5/6 
  Verifying        : mariadb-connector-c-config-3.1.11-2.el8_3.noarch                                                                                           6/6 

Installed:
  mysql-community-client-8.0.23-1.el8.x86_64         mysql-community-client-plugins-8.0.23-1.el8.x86_64         mysql-community-common-8.0.23-1.el8.x86_64        
  mysql-community-libs-8.0.23-1.el8.x86_64           mysql-community-server-8.0.23-1.el8.x86_64                

Complete!

启动Mysql

# 启动mysql
[root@WzcWyt wyt]# systemctl start mysqld

查看状态

# 查看状态
[root@WzcWyt wyt]# systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2021-04-21 13:40:40 CST; 9s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 5271 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 5347 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 23700)
   Memory: 483.4M
   CGroup: /system.slice/mysqld.service
           └─5347 /usr/sbin/mysqld

Apr 21 13:40:30 WzcWyt systemd[1]: Starting MySQL Server...
Apr 21 13:40:40 WzcWyt systemd[1]: Started MySQL Server.

查看’root’@'localhost创建的超级用户帐户及临时密码

[root@WzcWyt wyt]# sudo grep 'temporary password' /var/log/mysqld.log
2021-04-21T05:40:36.783755Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: yqyY&nHd%0#F

使用生成的临时密码登录

[root@WzcWyt wyt]# 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.23

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

进入mysq修改密码

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass4!';
Query OK, 0 rows affected (0.01 sec)

mysql> 

进入mysql配置mysql远程访问

1.进入mysql库

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>

2.查看root用户相关信息

mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root             | $A$005$FcJyCaM rC1&5g3
                                                       y<ZGc3Fm2GxPAAwKCGv/bLI0lddLtEHJC8qJJNABUDxbm1 | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql>

3.修改root用户host值(赋予任何主机访问数据的权限 )

mysql> update user set host='%' where user='root';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>

4.授权 root 用户的所有权限并设置远程访问

mysql> GRANT ALL ON *.* TO 'root'@'%';
Query OK, 0 rows affected (0.01 sec)

mysql> 

5.刷新权限,并查看

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

mysql> 

6.查看root 用户的 host 已经变成 %,远程访问mysql成功

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 host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| %         | root             | $A$005$FcJyCaM rC1&5g3
                                                       y<ZGc3Fm2GxPAAwKCGv/bLI0lddLtEHJC8qJJNABUDxbm1 | caching_sha2_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session    | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys        | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)

mysql> 

7.必须按以上流程操作不然会遇到一下问题
先执行第4部在执行第3部会报一下错:

mysql> GRANT ALL ON *.* TO 'root'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT

退出mysql

mysql> exit
Bye
[root@WzcWyt wyt]# 
mysql> quit
Bye
[root@WzcWyt wyt]#

停止Msyql服务

[root@WzcWyt wyt]# systemctl stop mysqld

设置开机启动mysql

[root@WzcWyt wyt]# systemctl enable mysqld

msyql配置文件路径

/etc/my.cnf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove the leading "# " to disable binary logging
# Binary logging captures changes between backups and is enabled by
# default. It's default setting is log_bin=binlog
# disable_log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
#
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
                                                                                                                                                 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值