Centos8.5安装mysql8.0

1.检查是否有安装mysql数据库(如果有mysql或者mariadb数据库,则卸载)

[root@myhost ~]# rpm -qa |grep mysql
[root@myhost ~]# rpm -qa | grep mariadb
[root@myhost ~]# ll /etc/my.cnf 
ls: 无法访问'/etc/my.cnf': No such file or directory
#如果有mysql或者mariadb数据库,则卸载
[root@myhost ~]# yum -y  remove `rpm -qa | grep mysql` 或者  yum -y  remove `rpm -qa | grep mariadb`  
[root@myhost ~]# ll  /etc/my.cnf
ls: 无法访问'/etc/my.cnf': No such file or directory
[root@myhost ~]# rpm -qa |grep mysql 或者 rpm -qa | grep mariadb

2.下载并安装mysql官方的 yum repository

[root@myhost ~]# cd /home/tools/
[root@myhost tools]# wget https://dev.mysql.com/get/mysql80-community-release-el7-4.noarch.rpm
[root@myhost tools]# ll
总用量 28
-rw-r--r--. 1 root root 25820 418 2018 mysql80-community-release-el7-4.noarch.rpm

3.rpm安装生成所需要的repo文件

[root@myhost tools]# ll /etc/yum.repos.d/
总用量 20
-rw-r--r--. 1 root root  941 1110 10:55 almalinux-ha.repo
-rw-r--r--. 1 root root  883 1110 10:55 almalinux-plus.repo
-rw-r--r--. 1 root root  961 1110 10:55 almalinux-powertools.repo
-rw-r--r--. 1 root root 2660 1110 10:55 almalinux.repo
-rw-r--r--. 1 root root 1022 1110 10:55 almalinux-resilientstorage.repo

[root@myhost tools]# rpm -ivh mysql80-community-release-el7-4.noarch.rpm
#执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件: mysql-community.repo 和 mysql-community-source.repo

[root@myhost tools]# ll /etc/yum.repos.d/                               
总用量 28
-rw-r--r--. 1 root root  941 1110 10:55 almalinux-ha.repo
-rw-r--r--. 1 root root  883 1110 10:55 almalinux-plus.repo
-rw-r--r--. 1 root root  961 1110 10:55 almalinux-powertools.repo
-rw-r--r--. 1 root root 2660 1110 10:55 almalinux.repo
-rw-r--r--. 1 root root 1022 1110 10:55 almalinux-resilientstorage.repo
-rw-r--r--. 1 root root 1864 222 2018 mysql-community.repo   ###新生成的repo文件###
-rw-r--r--. 1 root root 1885 222 2018 mysql-community-source.repo    ###新生成的repo文件###

4.正式安装mysql服务器

[root@myhost tools]# yum install -y mysql-server

[root@myhost tools]#  rpm -qa |grep mysql
mysql-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64
mysql-common-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64
mysql-server-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64
mysql80-community-release-el7-1.noarch
mysql-errmsg-8.0.26-1.module_el8.4.0+2532+b8928c02.x86_64

至此,mysql服务器安装完毕!!!

5.查看mysql 8.0 数据库主配置文件

[root@myhost tools]# ll /etc/my.cnf
-rw-r--r--. 1 root root 202 123 2020 /etc/my.cnf
[root@myhost tools]# cat /etc/my.cnf
#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d   ##这里引入MySQL 8.0 数据库各个详细配置文件##

[root@myhost tools]# ll /etc/my.cnf.d
总用量 12
-rw-r--r--. 1 root root 295 123 2020 client.cnf
-rw-r--r--. 1 root root 565 824 2021 mysql-default-authentication-plugin.cnf
-rw-r--r--. 1 root root 612 924 2021 mysql-server.cnf

服务端配置文件

[root@myhost tools]# cat /etc/my.cnf.d/mysql-server.cnf
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html

# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
#关闭ssl
ssl=0

6.启动mysql

### 启动mysql
[root@myhost tools]# systemctl start mysqld.service 

### 查看MySQL运行状态
[root@myhost tools]# systemctl status mysqld.service     
● mysqld.service - MySQL 8.0 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2022-05-05 03:07:44 EDT; 10s ago
  Process: 53994 ExecStartPost=/usr/libexec/mysql-check-upgrade (code=exited, status=0/SUCCESS)
  Process: 53862 ExecStartPre=/usr/libexec/mysql-prepare-db-dir mysqld.service (code=exited, status=0/SUCCESS)
  Process: 53837 ExecStartPre=/usr/libexec/mysql-check-socket (code=exited, status=0/SUCCESS)
 Main PID: 53947 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 23508)
   Memory: 460.1M
   CGroup: /system.slice/mysqld.service
           └─53947 /usr/libexec/mysqld --basedir=/usr

5月 05 03:07:35 myhost systemd[1]: Starting MySQL 8.0 database server...
5月 05 03:07:35 myhost mysql-prepare-db-dir[53862]: Initializing MySQL database
5月 05 03:07:44 myhost systemd[1]: Started MySQL 8.0 database server.

### 将MySQL加入开机自启动
[root@myhost tools]# systemctl enable mysqld.service           
Created symlink /etc/systemd/system/multi-user.target.wants/mysqld.service → /usr/lib/systemd/system/mysqld.service.

7.查看mysql的初始登录密码

当MySQL开始正常运行时,要想进入MySQL还得先找出此时root用户的密码,root用户的密码可以在MySQL日志文件中找出,前面安装MySQL时,服务端配置文件里面显示了MySQL的日志文件所在路径:log-error=/var/log/mysql/mysqld.log

[root@myhost tools]#  egrep -v "^#|^$"  /etc/my.cnf.d/mysql-server.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid

[root@myhost tools]# grep "password" /var/log/mysql/mysqld.log
2022-05-05T07:07:39.174205Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

根据日志中显示,此次安装mysql时没有设置root用户密码(即可以使用空密码进行登录)

8.登录mysql数据库

[root@myhost tools]# 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.26 Source distribution

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> 
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.26    |
+-----------+
1 row in set (0.00 sec)

mysql> 

此时不能做任何事情,因为MySQL默认必须修改密码之后才能操作数据库。

9.为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 host,user from mysql.user;
+-----------+------------------+
| host      | user             |
+-----------+------------------+
| localhost | mysql.infoschema |
| localhost | mysql.session    |
| localhost | mysql.sys        |
| localhost | root             |
+-----------+------------------+

mysql> alter user 'root'@'localhost' identified with by '新密码';
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 'by  'yuki12#$'' at line 1
mysql> set password=password('新密码');  
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 'password('yuki12#$')' at line 1
mysql> set authentication_string=password('新密码');  ### mysql的版本不一样,用户密码字段表示也不一样,这一点需要注意。
ERROR 1193 (HY000): Unknown system variable 'authentication_string'; 
mysql> 

上面修改root账户密码失败,原因在于在MySQL 8.02前,修改mysql的root账户密码可以直接使用:

set password=password('新密码');  
set authentication_string=password('新密码');  
alter user 'root'@'localhost' identified with by '新密码';

但MySQL8.0开始以后,这样默认是不行的。因为之前版本的mysql,使用的密码认证插件是“mysql_native_password”,而现在使用的是“caching_sha2_password”,但是我们修改密码必须使用的认证插件是“mysql_native_password”,所以MySQL8.0之后的版本在修改密码时要在sql语句中申明修改密码认证插件。

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.26    |
+-----------+
1 row in set (0.00 sec)

mysql> alter user 'root'@'localhost' identified with mysql_native_password by  '新密码';
Query OK, 0 rows affected (0.01 sec)

至此,成功修改root密码!!!

mysql> select host, user, password, plugin from user;                      
ERROR 1054 (42S22): Unknown column 'password' in 'field list'

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             | *1326652C75900CFF0EF7EF997D4D178B173CE182                              | mysql_native_password |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
4 rows in set (0.00 sec)


host:允许用户登录在哪个ip可以远程登录,%表示任意ip都可以远程登录mysql数据库;
user:当前数据库的用户名;
authentication_string:用户密码,在mysql 5.7.9以后废弃了password字段和password()函数;
plugin:密码加密方式;
我们看host和user两列,host和user中root对应的值为localhost,即root用户的访问权限为localhost,想把该用户的访问权限设置可远程连接,我们只需要把localhost更改为通配的%就可以了。上面的权限操作语句没有走通,这里就直接使用update语句来更改吧。

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

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

mysql> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host      | user             | authentication_string                                                  | plugin                |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| %         | root             | *1326652C75900CFF0EF7EF997D4D178B173CE182                              | mysql_native_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)

10.使用Navicat工具远程登录数据库(防火墙开启mysql端口的情况下)

![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/9a7040154e4641d4bf37ac25a3d35ad2.png
以上报错原因在于我们在安装的mysql8.0.26数据库时没有在配置文件中设置密码认证方式,此版本mysql默认的密码加密方式是:caching_sha2_password,而现在很多客户端工具还不支持这种加密认证方式,连接测试的时候就会报错。解决办法如下:

[root@myhost ~]# vi /etc/my.cnf.d/mysql-server.cnf 

#添加如下配置:default_authentication_plugin=mysql_native_password

[root@myhost ~]# systemctl restart mysqld.service    

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/721518.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

猫头虎分享已解决Bug || 前端领域技术问题解析

原创作者: 猫头虎 作者微信号: Libin9iOak 作者公众号: 猫头虎技术团队 更新日期: 2024年6月6日 博主猫头虎的技术世界 🌟 欢迎来到猫头虎的博客 — 探索技术的无限可能! 专栏链接: &…

python中scrapy

安装环境 pip install scrapy 发现Twisted版本不匹配 卸载pip uninstall Twisted 安装 pip install Twisted22.10.0 新建scrapy项目 scrapy startproject 项目名 注意:项目名称不允许使用数字开头,也不能包含中文 eg: scrapy startproject scrapy_baidu_…

Redis数据结构学习

Redis 关于redis相关的技术文章我一直没什么思路 直到最近的端午节,我偶然和一个程序员朋友聊到了关于redis数据结构相关的知识点, 所以我决定写一篇文章记录一下 首先我们需要知道redis支持哪些数据类型 Strings (字符串)Lists(列表)Hashes(哈希)Sets(集合)Sorted Sets(有序…

Transformer模型:未来的改进方向与潜在影响

Transformer模型:未来的改进方向与潜在影响 自从2017年Google的研究者们首次提出Transformer模型以来,它已经彻底改变了自然语言处理(NLP)领域的面貌。Transformer的核心优势在于其“自注意力(Self-Attention&#xf…

【C语言习题】31.冒泡排序

文章目录 作业标题作业内容2.解题思路3.具体代码 作业标题 冒泡排序 作业内容 实现一个对整形数组的冒泡排序 2.解题思路 先了解一下冒泡排序: 两两相邻的元素进行比较,如果前面元素大于后面元素就交换两个元素的位置,最终的结果是最大的…

RERCS系统开发实战案例-Part08 FPM 应用程序的表单组件(From UIBB)与列表组件(List UIBB)组合的创建

1、新建From UIBB的FPM Application的快速启动面板 备注:该步骤可第一步操作,也可最后一步操作,本人习惯第一步操作。 1)使用事务码 LPD_CUST,选择对应的角色与实例进入快速启动板定制页面; 2&#xff09…

pg表空间和mysql表空间的区别

一、表空间的定义 1、在pg中表空间实际上是为表指定一个存储的目录。并且在创建数据库时可以为数据库指定默认的表空间。创建表和索引时可以指定表空间,这样表和索引就可以存储到表空间对应的目录下了。 在pg中一个库中可以有多个表空间,一个表空间可以…

U盘量产经历二——phisonPS2251-70(PS2270)

写在前面: 量产相关的BBS看了挺多,phison群联的芯片PS2251-70(PS2270)的量产工具比较少,而且很难下载。这里我访问了国外的网站下载来了,也贴出来给童鞋们取用。 以下是记录的量产过程: https://www.usbdev.ru 工具…

Linux操作系统学习:day04

内容来自:Linux介绍 视频推荐:[Linux基础入门教程-linux命令-vim-gcc/g -动态库/静态库 -makefile-gdb调试]( 目录 day0422、通过文字设定法修改用户对文件的操作权限23、通过数字设定法修改文件的权限24、修改文件所有者和所属组25、tree—查看目录内…

国际荐酒师香港协会受邀参加2024年美国独立日庆祝活动

国际荐酒师(香港)协会受邀参加2024年美国独立日庆祝活动促进世界酒中国菜的全球化发展 2024年6月18日,国际荐酒师(香港)协会大中华区驻广州办事处荣幸地接受了美国驻广州总领事馆 Nicholas Burns大使和Lisa Heller总领…

python修改pip install 默认安装路径

第一步:通过win菜单,找到Prompt,点击进入 第二步:在cmd里输入 python -m site获得: D:\ProgramData\Anaconda3 ----》是Anaconda安装的位置USER_BASE: C:\Users\kevin… ----》表示默认路径在C盘USER_SITE: C:\Users\kevin… ----》表示默认路径在C盘1.2 修改pip 默认安…

使用Minikube部署Kubernetes环境

使用Minikube部署Kubernetes环境 1. Minikube简介 Minikube是一个轻量级的Kubernetes实现,它在本地运行一个Kubernetes集群,可以是单节点或者集群环境,主要用于开发和测试。Minikube支持Kubernetes的所有主要功能,包括Dashboard…

C#——方法的参数列表ref、out、params、in详情

在C#中,方法参数列表是在定义方法时指定的,用于接收传递给方法的数据。参数列表包括参数类型和参数名。参数可以是必需的(必须有值),也可以是可选的(可以有默认值)。 方法的参数列表 1. 值参数…

温湿度采集与OLED显示

目录 一、什么是软件I2C 二、什么是硬件I2C 三、STM32CubeMX配置 1、RCC配置 2、SYS配置 3、I2C1配置 3、I2C2配置 4、USART1配置 5、TIM1配置 6、时钟树配置 7、工程配置 四、设备链接 1、OLED连接 2、串口连接 3、温湿度传感器连接 五、每隔2秒钟采集一次温湿…

jquey+mybatis-plus实现简单分页功能

这篇文章介绍一下怎么通过JQuery结合mybatis-plus的分页插件实现原生HTML页面的分页效果,没有使用任何前端框架,主要是对前端知识的应用。 创建Springboot项目 Intellij IDEA中创建一个Springboot项目,项目名为pager。 添加必须的依赖包 修…

Linux安装Tomcat和Nginx

目录 前言一、系统环境二、Tomcat安装步骤Step1 安装JDK环境Step2 安装Tomcat 三、Nginx安装步骤四、测试4.1 测试Tomcat4.2 测试Nginx 总结 前言 本篇文章介绍如何在Linux上安装Tomcat web服务器。 一、系统环境 虚拟机版本:VMware Workstation 15 ProLinux镜像…

Java基础 - 练习(二)打印菱形

Java基础练习 打印菱形&#xff0c;先上代码&#xff1a; // 方法一&#xff1a;基础&#xff0c;好理解 public static void diamond() {//控制行数for (int i 1; i < 4; i) {//空格的个数for (int k 1; k < 4 - i; k) {System.out.print(" ");}//控制星星…

链表OJ--超详细解析

链表OJ 文章目录 链表OJ1. 反转链表2. 返回K值3. 链表的中间节点4. 回文链表5. 相交链表6. 带环链表6.1 为什么一定会相遇&#xff0c;有没有可能会错过&#xff0c;或者出现永远追不上的情况&#xff0c;请证明6.2 slow一次走一步&#xff0c;fast如果一次走3步&#xff0c;走…

解决nvm切换node版本后,全局依赖无法使用

问题描述 使用 nvm install 10.24.1 安装node版本&#xff0c;安装成功后&#xff0c;使用 npm install -g xxx 安装全局依赖&#xff08;私有库&#xff09;&#xff0c;安装成功后&#xff0c;运行命令提示找不到命令。 已做以下尝试 npm root -g&#xff0c;返回 D:\Prog…

【Java面试】二十、JVM篇(上):JVM结构

文章目录 1、JVM2、程序计数器3、堆4、栈4.1 垃圾回收是否涉及栈内存4.2 栈内存分配越大越好吗4.3 方法内的局部变量是否线程安全吗4.4 栈内存溢出的情况4.5 堆和栈的区别是什么 5、方法区5.1 常量池5.2 运行时常量池 6、直接内存 1、JVM Java源码编译成class字节码后&#xf…