Linux(CentOS8)系统安装mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2024-08-27 12:36

本文主要是介绍Linux(CentOS8)系统安装mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、下载获取 mysql安装包;

MySQL :: Download MySQL Community Server (Archived Versions)

二、安装步骤

1、切换到安装目录下,并解压

tar -zxvf mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz

2.移动解压后的文件并且重命名为mysql

 mv mysql-8.0.26-linux-glibc2.12-x86_64 /usr/local

 3.先切换至mysql文件夹下创建新文件夹data

cd /usr/local/mysql

 

4.创建mysql用户组和mysql用户

groupadd mysql

useradd -g mysql mysql 

 5.修改mysql目录权限

chown -R mysql.mysql /usr/local/mysql/

6.数据库初始化

注意事项:记录一下mysql数据库的临时密码*************,后面安装步骤是需要使用的!

./bin/mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --initialize

 7.修改my.cnf文件

vi  /etc/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命令,保存并退出 

8.创建mysql服务 

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

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

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

按照顺序执行!

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld 
chkconfig --add mysqld 

9.配置环境变量 

vi /etc/profile

将下面配置添加到export 环境变量配置文件中

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

设置环境变量立即生效

source /etc/profile 

10.启动mysql服务

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

[root ~]# service mysql start
Redirecting to /bin/systemctl start mysql.service
[root ~]# 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. 

11.登陆mysql并且修改密码

这里输入的密码为 第 6 步初始化的默认密码

[root ~]# 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> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root123456';
Query OK, 0 rows affected (0.01 sec)
mysql> 

12.设置mysql远程登录后可使用客户端进行连接 

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

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

c)刷新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>

这篇关于Linux(CentOS8)系统安装mysql-8.0.26-linux-glibc2.12-x86_64.tar.xz的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1111687

相关文章

MySQL常用字符串函数示例和场景介绍

《MySQL常用字符串函数示例和场景介绍》MySQL提供了丰富的字符串函数帮助我们高效地对字符串进行处理、转换和分析,本文我将全面且深入地介绍MySQL常用的字符串函数,并结合具体示例和场景,帮你熟练... 目录一、字符串函数概述1.1 字符串函数的作用1.2 字符串函数分类二、字符串长度与统计函数2.1

Oracle数据库定时备份脚本方式(Linux)

《Oracle数据库定时备份脚本方式(Linux)》文章介绍Oracle数据库自动备份方案,包含主机备份传输与备机解压导入流程,强调需提前全量删除原库数据避免报错,并需配置无密传输、定时任务及验证脚本... 目录说明主机脚本备机上自动导库脚本整个自动备份oracle数据库的过程(建议全程用root用户)总结

SQL Server跟踪自动统计信息更新实战指南

《SQLServer跟踪自动统计信息更新实战指南》本文详解SQLServer自动统计信息更新的跟踪方法,推荐使用扩展事件实时捕获更新操作及详细信息,同时结合系统视图快速检查统计信息状态,重点强调修... 目录SQL Server 如何跟踪自动统计信息更新:深入解析与实战指南 核心跟踪方法1️⃣ 利用系统目录

MySQL 内存使用率常用分析语句

《MySQL内存使用率常用分析语句》用户整理了MySQL内存占用过高的分析方法,涵盖操作系统层确认及数据库层bufferpool、内存模块差值、线程状态、performance_schema性能数据... 目录一、 OS层二、 DB层1. 全局情况2. 内存占js用详情最近连续遇到mysql内存占用过高导致

Linux如何查看文件权限的命令

《Linux如何查看文件权限的命令》Linux中使用ls-R命令递归查看指定目录及子目录下所有文件和文件夹的权限信息,以列表形式展示权限位、所有者、组等详细内容... 目录linux China编程查看文件权限命令输出结果示例这里是查看tomcat文件夹总结Linux 查看文件权限命令ls -l 文件或文件夹

idea的终端(Terminal)cmd的命令换成linux的命令详解

《idea的终端(Terminal)cmd的命令换成linux的命令详解》本文介绍IDEA配置Git的步骤:安装Git、修改终端设置并重启IDEA,强调顺序,作为个人经验分享,希望提供参考并支持脚本之... 目录一编程、设置前二、前置条件三、android设置四、设置后总结一、php设置前二、前置条件

Mysql中设计数据表的过程解析

《Mysql中设计数据表的过程解析》数据库约束通过NOTNULL、UNIQUE、DEFAULT、主键和外键等规则保障数据完整性,自动校验数据,减少人工错误,提升数据一致性和业务逻辑严谨性,本文介绍My... 目录1.引言2.NOT NULL——制定某列不可以存储NULL值2.UNIQUE——保证某一列的每一

解密SQL查询语句执行的过程

《解密SQL查询语句执行的过程》文章讲解了SQL语句的执行流程,涵盖解析、优化、执行三个核心阶段,并介绍执行计划查看方法EXPLAIN,同时提出性能优化技巧如合理使用索引、避免SELECT*、JOIN... 目录1. SQL语句的基本结构2. SQL语句的执行过程3. SQL语句的执行计划4. 常见的性能优

SQL Server 中的 WITH (NOLOCK) 示例详解

《SQLServer中的WITH(NOLOCK)示例详解》SQLServer中的WITH(NOLOCK)是一种表提示,等同于READUNCOMMITTED隔离级别,允许查询在不获取共享锁的情... 目录SQL Server 中的 WITH (NOLOCK) 详解一、WITH (NOLOCK) 的本质二、工作

MySQL 强制使用特定索引的操作

《MySQL强制使用特定索引的操作》MySQL可通过FORCEINDEX、USEINDEX等语法强制查询使用特定索引,但优化器可能不采纳,需结合EXPLAIN分析执行计划,避免性能下降,注意版本差异... 目录1. 使用FORCE INDEX语法2. 使用USE INDEX语法3. 使用IGNORE IND