1、MySQL 8.0.26 下载

官方网站下载 MySQL 8.0.26 安装包,下载地址:

https://downloads.mysql.com/archives/community/

需要注意:Linux操作系统是32位还是64位,本案例采用Linux 64位操作系统进行讲解,通过wget命令下载安装包。

使用df -lh命令查看,磁盘大小,尽量安装在比较大的磁盘下,防止空间不够使用。

[root@VM-0-4-centos home]# df -lh
Filesystem Size Used Avail Use% Mounted on
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 24K 3.9G 1% /dev/shm
tmpfs 3.9G 604K 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/vda1 50G 3.8G 44G 9% /
tmpfs 783M 0 783M 0% /run/user/0

通过上述命令可以看出根目录空间比较充足,那么就把安装包下载到home目录了,执行wget命令。

[root@VM-0-4-centos home]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

  

2、解压缩文件

解压 mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 文件,使用tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz 命令。

[root@VM-0-4-centos home]# tar -xvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz
mysql-8.0.26-linux-glibc2.12-x86_64/bin/
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisam_ftdump
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamchk
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisamlog
mysql-8.0.26-linux-glibc2.12-x86_64/bin/myisampack
mysql-8.0.26-linux-glibc2.12-x86_64/bin/mysql
....
mysql-8.0.26-linux-glibc2.12-x86_64/share/
mysql-8.0.26-linux-glibc2.12-x86_64/share/install_rewriter.sql
mysql-8.0.26-linux-glibc2.12-x86_64/share/uninstall_rewriter.sql

  

3、移动文件

将压缩包移动到usr/local目录下,并重命名文件为mysql,使用mv /home/mysql-8.0.26-linux-glibc2.12-x86_64  /usr/local/mysql命令。

[root@VM-0-4-centos home]# mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local/mysql
[root@VM-0-4-centos home]# cd /usr/local/mysql/
[root@VM-0-4-centos mysql]# ls
bin docs include lib LICENSE man README share support-files
[root@VM-0-4-centos mysql]# cd ..
[root@VM-0-4-centos local]# ls
bin etc games include lib lib64 libexec mysql qcloud sbin share src yd.socket.server
[root@VM-0-4-centos local]#

  

4、创建数据存放目录

在mysql根目录下新建一个目录data,主要用于存放数据库数据文件,使用mkdir data命令。

[root@VM-0-4-centos local]# cd mysql/
[root@VM-0-4-centos mysql]# mkdir data
[root@VM-0-4-centos mysql]# ls
bin data docs include lib LICENSE man README share support-files
[root@VM-0-4-centos mysql]#

  

5、创建用户组和用户

创建mysql用户组和mysql用户,使用groupadd mysql和useradd -g mysql mysql命令。

[root@VM-0-4-centos mysql]# groupadd mysql
[root@VM-0-4-centos mysql]# useradd -g mysql mysql

  

6、改变mysql目录权限

修改mysql目录权限,可以使用chown -R mysql.mysql /usr/local/mysql/命令。

修改mysql目录权限也可以通过chown -R mysql .和chgrp -R mysql .两个命令。注意:这两个命令都需要执行的,还有那个点不要忽视掉。

7、数据库初始化

数据库初始化./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize命令,得到临时密码。

2022-01-16T07:32:18.729960Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.26) initializing of server in progress as process 7691
2022-01-16T07:32:18.740975Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-01-16T07:32:19.800287Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-01-16T07:32:21.721672Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-01-16T07:32:21.722106Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-01-16T07:32:21.787669Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: j-6lA2aXv=Pz

需要注意:记录一下mysql数据库的临时密码 j-6lA2aXv=Pz,后面安装步骤是需要使用的,否则需要重新安装数据库或其他方式获取密码,此处问题省略。另外,关于更多其他软件安装配置步骤,如redis、kafka、fastdfs、elasticsearch等中间件安装配置图文步骤,公众号Java精选,回复中间件三个汉字,获取所有软件安装步骤。切勿乱回复,否则什么也没有!!!

8、修改my.cnf文件

修改my.cnf文件,使用vim my.cnf命令。

[mysqld]
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /usr/local/mysql/mysql.sock
character-set-server=utf8
port = 3306
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[client]
socket = /usr/local/mysql/mysql.sock
default-character-set=utf8
#[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0
# 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 mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd #[mysqld_safe]
#log-error=/var/log/mariadb/mariadb.log
#pid-file=/var/run/mariadb/mariadb.pid #
# include all files from the config directory
#
#!includedir /etc/my.cnf.d

直接将上述配置内容复制到my.cnf文件中,或者自行修改,然后执行:wq命令,保存并退出。

9、创建mysql服务

1)将mysql.server启动文件复制到/etc/init.d目录,使用cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld命令。

2)赋予权限,使用chmod +x /etc/rc.d/init.d/mysqld命令;

3)使用chkconfig --add mysqld创建mysql服务。

[root@VM-0-4-centos mysql]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@VM-0-4-centos mysql]# chmod +x /etc/rc.d/init.d/mysqld
[root@VM-0-4-centos mysql]# chkconfig --add mysqld

检查mysql服务是否生效,使用chkconfig  --list mysqld命令。

[root@VM-0-4-centos mysql]# chkconfig  --list mysqld

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration. If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'. mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

  

10、配置全局环境变量

编辑/etc/profile文件,使用vim /etc/profile命令,在profile文件中添加如下两行配置,使用:wq命令保存后退出。

export PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql/lib
export PATH

设置环境变量立即生效使用source /etc/profile命令。

[root@VM-0-4-centos ~]# source /etc/profile
[root@VM-0-4-centos ~]#

  

11、启动mysql服务

启动mysql服务,使用service mysql start命令;使用service mysql status命令,查看是否启动成功。

[root@VM-0-4-centos ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root@VM-0-4-centos ~]# service mysql status
Redirecting to /bin/systemctl status mysql.service
● mysqld.service - LSB: start and stop MySQL
Loaded: loaded (/etc/rc.d/init.d/mysqld; bad; vendor preset: disabled)
Active: active (running) since Sun 2022-01-16 17:17:55 CST; 8s ago
Docs: man:systemd-sysv-generator(8)
Process: 27231 ExecStart=/etc/rc.d/init.d/mysqld start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mysqld.service
├─27242 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/VM-0-4-centos.pid
└─27408 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=VM-0-4-cent... Jan 16 17:17:54 VM-0-4-centos systemd[1]: Starting LSB: start and stop MySQL...
Jan 16 17:17:54 VM-0-4-centos mysqld[27231]: Starting MySQL.Logging to '/usr/local/mysql/data/VM-0-4-centos.err'.
Jan 16 17:17:55 VM-0-4-centos mysqld[27231]: SUCCESS!
Jan 16 17:17:55 VM-0-4-centos systemd[1]: Started LSB: start and stop MySQL.

  

12、登录mysql修改密码

登录mysql数据库,使用mysql -uroot -p密码命令,临时密码是j-6lA2aXv=Pz。

[root@VM-0-4-centos ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 8.0.26 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临时密码,也就是将第七步数据库初始化生成的临时密码修改成自己需要设置的密码。

修改mysql数据库密码,使用ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';命令。

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

注意:此处123456修改为自己的需要密码即可。

13、设置mysql远程登录

1)切换数据库,使用use mysql;命令。

2)修改mysql库中host值,使用update user set host='%' where user='root' limit 1;命令。

3)刷新mysql权限,使用flush privileges;命令。

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> update user set host='%' where user='root' limit 1;
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0 mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql>

  

14、mysql客户端连接数据库

客户端连接mysql数据库,连接名(自定义名称)、主机(IP)、端口号及用户名和密码,点击测试连接按钮,显示连接成功即可。

注意:若提示无法连接,需要测试服务器3306端口是否开放。若服务器端可以通过查看防火墙情况,此时方式验证省略;而从客户端测试可以使用“telnet IP 端口号”命令。

Linux 安装 MySQL 8.0.26 超详细图文步骤的更多相关文章

  1. 硬盘安装CentOS 6.0(超级详细图文教程)

    硬盘安装CentOS 6.0(超级详细图文教程) 来源:   引言: 电脑系统是Windows XP,电脑没有光驱.手头没有U盘.没有移动硬盘.电脑主板不支持U盘启动,在这种情况下想安装CentOS ...

  2. CentOS 7安装MySQL 8——萌新超详细教程

          1.配置MySQL 8.0的安装源:   sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-1.n ...

  3. Linux安装mysql.8.0.12

    1. linux安装mysql8.0.12,亲测可用. 以下是安装过程中出现的问题: 1 [root@localtest1 file]# systemctl start mysqld 2 Job fo ...

  4. Linux中安装MySql 5.7.21的详细操作步骤

    一:到mysql官网下载最新的mysql包 mysql-5.7.21-linux-glibc2.12-x86_64 官方下载地址:https://dev.mysql.com/downloads/mys ...

  5. Linux 安装 MySQL 8 数据库(图文详细教程)

    本教程手把手教你如何在 Linux 安装 MySQL 数据库,以 CentOS 7为例. 1. 下载并安装 MySQL 官方的 Yum Repository wget -i -c https://re ...

  6. 安装64位Oracle 10g超详细教程

    安装64位Oracle 10g超详细教程 1. 安装准备阶段 1.1 安装Oracle环境 经过上一篇博文的过程,已经完成了对Linux系统的安装,本例使用X-Manager来实现与Linux系统的连 ...

  7. 在 CentOS 7.5 64位上使用 yum 安装 MySQL 8.0

    前段时间在 CentOS 7.5 64位上安装 MySQL 8.0.查了些资料,在这里记录一下详细的安装和设置步骤. 一.安装 使用yum安装MySQL之前需要先下载对应的.rpm文件,下载方法: 去 ...

  8. linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题]

    linux安装mysql全纪录[包括yum和rpm安装,编码,远程连接以及大小写问题] 一.查看mysql是否已经安装 使用“whereis mysql”命令来查看mysql安装路径: [root@h ...

  9. Linux 安装Mysql(图文教程)

    原文:Linux 安装Mysql(图文教程) 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net ...

随机推荐

  1. [BUUCTF]PWN18——bjdctf_2020_babystack

    [BUUCTF]PWN18--bjdctf_2020_babystack 附件 步骤: 例行检查,64位,开启了nx保护 试运行一下程序 大概了解程序的执行过程后用64位ida打开,shift+f12 ...

  2. 【WP】【web】中学生CTF | web部分wp

    $_GET 源码: <?php show_source(__FILE__); include 'config.php'; if(!isset($_GET['args'])){ die(); } ...

  3. 调配资源(Project)

    <Project2016 企业项目管理实践>张会斌 董方好 编著 当资源过度分配了,肿么办? 比如前面的例子,某吃货甲,一天之内给他分配了9.6个工时的吃量,这怎么可以呢,让人加班是不厚道 ...

  4. 对ORM的理解

    1. 在面试中可能会问到这个问题,什么是ORM? ORM是对象关系映射(Object Relational Mapping),简称ORM,或O/RM,或O/R mapping,是一种程序技术. 白话理 ...

  5. LuoguP6861 [RC-03] 难题 题解

    Update \(\texttt{2020.10.21}\) 删除了不需要的 \(n=1\) 的特判,并在符号与字母之间添加了空格. Content 给定一个数 \(n\),试找到一对数 \(a,b( ...

  6. JavaScript数组的push()等方法的使用

    数组是值得有序集合.每个值在数组中有一个位置,用数字表示,叫做索引.JavaScript数组是无类型的:数组元素可以是任何类型,而且同一个数组中可以存在不同类型元素,甚至可以是对象或是其他数组,这就可 ...

  7. linux下记录入站请求

    将内网机器通过frp映射到公网后,内网主机受到大量ssh爆破攻击,攻击来源为frp的服务端,仅在内网机器上无法追踪到真实的攻击来源的ip.下面记录了在frp服务端监控指定端口的入站数据,找到真正的攻击 ...

  8. Spring学习(五)Spring和Mybatis的整合

    1.前言 在整合之前.要搞清楚是谁整合谁.后续会学到很多整合的例子.在这里.是Spring整合Mybatis.Spring中集成了很多关于Mybatis中一些关键类的jar包.通过这些.可以更加方便的 ...

  9. MyBatis学习(二)MyBatis-Statement方式的增删改查

    1.前期准备 项目骨架图如下所示 1.配置conf.xml <?xml version="1.0" encoding="UTF-8" ?> < ...

  10. 【LeetCode】987. Vertical Order Traversal of a Binary Tree 解题报告(C++ & Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 DFS BFS 日期 题目地址:https://le ...