搜索
首页数据库mysql教程Centos7.9安装MySQL8.0.32的方法是什么

Centos7.9安装MySQL8.0.32的方法是什么

May 30, 2023 pm 01:46 PM
mysqlcentos

第一步、下载压缩包

下载社区版的 MySQL,根据需求下载对应版本,其中有最小安装版本。

Centos7.9安装MySQL8.0.32的方法是什么

第二步,解压压缩包,并复制到安装目录

进入到压缩包所在的文件夹,解压分为两次,第一次解压 xz 文件,第二次解压 tar 文件。

xz -dv mysql-8.0.32-linux-glibc2.12-x86_64.tar.xz
tar -xvf mysql-8.0.32-linux-glibc2.12-x86_64.tar

复制解压后的文件到到要安装的目录,我要把 MySQL 安装到/usr/local/mysql,所以,运行以下命令,把解压后的文件复制过去

sudo cp -r mysql-8.0.32-linux-glibc2.12-x86_64/* /usr/local/mysql

这里需要修改以下安装目录的权限,由于我们使用 mysql 用户运行数据库,所以,要把安装目录的拥有者改为 mysql,如果系统没有,需要添加 mysql 用户及分组,我们只使用 mysql 运行程序,所以指定了 mysql 禁止登录,增加安全性

sudo groupadd mysql
sudo useradd mysql -s /usr/sbin/nologin -g mysql

修改安装目录的拥有者为 mysql

chown -R mysql:mysql /usr/local/mysql/

第三步、编辑配置文件

编辑配置文件,我们把配置文件放到 /etc/my.cnf

配置如下:

[client]
port=3306
# 端口
# mysqlx_port=33060
socket=/var/lib/mysql/mysql.sock
# mysqlx_socket=/var/lib/mysqlx.sock

[mysqld]
# skip-grant-tables
# mysql安装目录
basedir=/usr/local/mysql/
# mysql数据库目录
datadir=/var/lib/mysql/data/
port=3306
innodb_file_per_table=1
character-set-server=UTF8MB4
mysqlx_port=33060
socket = /var/lib/mysql/mysql.sock
# mysqlx_socket=/var/lib/mysql/mysqlx.sock

[mysqld_safe]
# 错误日志
log-error=/var/log/mysql/error.log
# pid文件
pid-file=/usr/local/mysql/mysqld.pid
tmpdir=/var/lib/mysql/mysql

第四步、确定一些相关的目录

编辑文件support-files/mysql.server,修改里面的相关目录

安装目录 basedir=/usr/local/mysql

配置目录 /etc/my.cnf

数据库文件目录 datadir=/var/lib/mysql/data/

pid 文件pid-file=/usr/local/mysql/mysqld.pid

第五步、初始化数据库

初始化数据库,注意,初始化成功后,终端会显示 root 账号密码,一定要保存下来

sudo ./bin/mysqld --defaults-file=/etc/my.cnf --user=mysql --initialize

第六步、启动数据库,连接并修改 root 密码

sudo ./bin/mysqld --defaults-file=/etc/my.cnf --user=mysql

连接数据库,修改 root 密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '你的密码';

第六步、守护 MySQL 进程

创建守护程序,保证在服务器重启后能够自动启动,运行

sudo vim /etc/systemd/system/mysql.service

内容如下,其中 User 和 Group 为 mysql

[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
After=network.target
After=syslog.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#Restart=on-failure
#RestartPreventExitStatus=1
#PrivateTmp=false
# 使能
sudo systemctl enable mysql.service
# 启动
sudo systemctl start mysql.service
# 查看状态
sudo systemctl status mysql.service

第七步、验证

重启服务器验证 mysql 进程是否启动

以上是Centos7.9安装MySQL8.0.32的方法是什么的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文转载于:亿速云。如有侵权,请联系admin@php.cn删除
如何在MySQL中删除或修改现有视图?如何在MySQL中删除或修改现有视图?May 16, 2025 am 12:11 AM

todropaviewInmySQL,使用“ dropviewifexistsview_name;” andTomodifyAview,使用“ createOrreplaceViewViewViewview_nameAsSelect ...”。whendroppingaview,asew dectivectenciesanduse和showcreateateviewViewview_name;“ tounderStanditSsstructure.whenModifying

MySQL视图:我可以使用哪些设计模式?MySQL视图:我可以使用哪些设计模式?May 16, 2025 am 12:10 AM

mySqlViewScaneFectectialized unizedesignpatternslikeadapter,Decorator,Factory,andObserver.1)adapterPatternadaptSdataForomDifferentTablesIntoAunifiendView.2)decoratorPatternenhancateDataWithCalcalcualdCalcalculenfields.3)fieldfields.3)

在MySQL中使用视图的优点是什么?在MySQL中使用视图的优点是什么?May 16, 2025 am 12:09 AM

查看InMysqlareBeneForsImplifyingComplexqueries,增强安全性,确保dataConsistency,andOptimizingPerformance.1)他们simimplifycomplexqueriesbleiesbyEncapsbyEnculatingThemintoreusableviews.2)viewsEnenenhancesecuritybyControllityByControllingDataAcces.3)

如何在MySQL中创建一个简单的视图?如何在MySQL中创建一个简单的视图?May 16, 2025 am 12:08 AM

toCreateAsimpleViewInmySQL,USEthecReateaTeviewStatement.1)defitEtheetEtheTeViewWithCreatEaTeviewView_nameas.2)指定usethectstatementTorivedesireddata.3)usethectStatementTorivedesireddata.3)usetheviewlikeatlikeatlikeatlikeatlikeatlikeatable.views.viewssimplplifefifydataaccessandenenanceberity but consisterfort,butconserfort,consoncontorfinft

MySQL创建用户语句:示例和常见错误MySQL创建用户语句:示例和常见错误May 16, 2025 am 12:04 AM

1)foralocaluser:createUser'localuser'@'@'localhost'Indidendify'securepassword'; 2)foraremoteuser:creationuser's creationuser'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Remoteer'Rocaluser'@'localhost'Indidendify'seceledify'Securepassword'; 2)

在MySQL中使用视图的局限性是什么?在MySQL中使用视图的局限性是什么?May 14, 2025 am 12:10 AM

mysqlviewshavelimitations:1)他们不使用Supportallsqloperations,限制DatamanipulationThroughViewSwithJoinSorsubqueries.2)他们canimpactperformance,尤其是withcomplexcomplexclexeriesorlargedatasets.3)

确保您的MySQL数据库:添加用户并授予特权确保您的MySQL数据库:添加用户并授予特权May 14, 2025 am 12:09 AM

porthusermanagementInmysqliscialforenhancingsEcurityAndsingsmenting效率databaseoperation.1)usecReateusertoAddusers,指定connectionsourcewith@'localhost'or@'%'。

哪些因素会影响我可以在MySQL中使用的触发器数量?哪些因素会影响我可以在MySQL中使用的触发器数量?May 14, 2025 am 12:08 AM

mysqldoes notimposeahardlimitontriggers,butacticalfactorsdeterminetheireffactective:1)serverConfiguration impactactStriggerGermanagement; 2)复杂的TriggerSincreaseSySystemsystem load; 3)largertablesslowtriggerperfermance; 4)highConconcConcrencerCancancancancanceTigrignecentign; 5); 5)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3 Linux新版

SublimeText3 Linux新版

SublimeText3 Linux最新版

SublimeText3 英文版

SublimeText3 英文版

推荐:为Win版本,支持代码提示!

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。