如何在Debian11上安装MysqlServer8
MySQL是一个开源的关系数据库管理系统,它是流行的关系型数据库之一。
Mysql通常作为流行的LAMP或LEMP(Linux、ApacheNginx、MySQLMariaDB、PHPPythonPerl)堆栈的一部分安装,它实现了关系模型和结构化查询语言(SQL)来管理和查询数据。
在本指南中,我们将在Debian11上安装mysql8。1。确保服务器是最新的
在开始之前,让我们确保我们的debian服务器是最新的,使用此命令更新服务器包:sudoaptupdatesudoaptupgradey
接下来,让我们安装我们在教程中需要的常用包sudoaptinstallycurlvim2。为mysql8安装设置repo
Mysqlserver8在默认的Debian存储库中不可用,mysql团队提供了一个可下载的。deb文件,该文件将为mysqlserver8安装配置存储库,使用以下命令下载它:curlLOhttps:dev。mysql。comgetmysqlaptconfig0。8。201all。deb
您应该会看到与此几乎相似的输出:curlLOhttps:dev。mysql。comgetmysqlaptconfig0。8。201all。debTotalReceivedXferdAverageSpeedTimeTimeTimeCurrentDloadUploadTotalSpentLeftSpeed00000000::::::0100355481003554800104k0::::::104k
下载完成后,我们需要安装下载的deb文件,使用此命令安装:sudodpkgi。mysqlaptconfig0。8。201all。deb
这将打开一个配置窗口,提示您选择mysql服务器版本和其他组件,例如集群、共享客户端库或MySQL工作台。
现在因为我们只对MysqlServer安装感兴趣,所以保留默认(MysqlServer和集群)设置并单击OK继续。
这是成功安装和配置的输出。sudodpkgi。mysqlaptconfig0。8。201all。debsudo:unabletoresolvehostdebiansrv。citizix。com:Noaddressassociatedwithhostname(Readingdatabase。。。30001filesanddirectoriescurrentlyinstalled。)Preparingtounpack。。。mysqlaptconfig0。8。201all。deb。。。Unpackingmysqlaptconfig(0。8。201)over(0。8。201)。。。Settingupmysqlaptconfig(0。8。201)。。。Warning:aptkeyshouldnotbeusedinscripts(calledfrompostinstmaintainerscriptofthepackagemysqlaptconfig)Warning:aptkeyisdeprecated。Managekeyringfilesintrusted。gpg。dinstead(seeaptkey(8))。OK3。安装Mysql8服务器
现在已经添加了repos以包含mysql服务器,我们现在可以安装mysqlserver包。
首先,刷新存储库以从添加的存储库中获取最新信息:sudoaptupdate
然后使用以下命令安装Mysql8Server:sudoaptinstallymysqlserver
输入您的管理员凭据,系统将安装MySQL服务器包、客户端包和数据库公共文件。
安装将提示您输入并确认MySQL数据库的root用户和密码。
使用此命令检查已安装包的信息以确认我们安装了我们想要的mysql版本:aptcachepolicymysqlservermysqlserver:Installed:8。0。271debian11Candidate:8。0。271debian11Versiontable:8。0。271debian11500500http:repo。mysql。comaptdebianbullseyemysql8。0amd64Packages100varlibdpkgstatus4。启动和启用mysql服务
在debian中,Mysql服务器默认是styarted。检查服务的状态以确认它实际上正在运行:sudosystemctlstatusmysqlsudo:unabletoresolvehostdebiansrv。citizix。com:Noaddressassociatedwithhostnamemysql。serviceMySQLCommunityServerLoaded:loaded(libsystemdsystemmysql。service;enabled;vendorpreset:enabled)Active:active(running)sinceWed2021112404:47:23UTC;2min31sagoDocs:man:mysqld(8)http:dev。mysql。comdocrefmanenusingsystemd。htmlProcess:15747ExecStartPreusrsharemysql8。0mysqlsystemdstartpre(codeexited,status0MainPID:15782(mysqld)Status:ServerisoperationalTasks:37(limit:4626)Memory:356。7MCPU:911msCGroup:system。slicemysql。service15782usrsbinmysqldNov2404:47:22debiansrv。citizix。comsystemd〔1〕:StartingMySQLCommunityServer。。。Nov2404:47:23debiansrv。citizix。comsystemd〔1〕:StartedMySQLCommunityServer。
在Active:active(running)since。。。表示该服务是启动和运行。
要使服务在重新启动时启动,请使用以下命令:sudosystemctlenablemysql
使用journalctl命令查看MySQL8服务日志如下:sudojournalctlumysqlxesudotailfvarlogmysqlmysqld。log5。测试MySQL安装
让我们使用以下命令检查mysql版本:mysqlVmysqlVer8。0。27forLinuxonx8664(MySQLCommunityServerGPL)
现在您可以root使用上面指定的用户和密码登录。mysqlurootpEnterpassword:WelcometotheMySQLmonitor。Commandsendwith;org。YourMySQLconnectionidis8Serverversion:8。0。27MySQLCommunityServerGPLCopyright(c)2000,2021,Oracleandoritsaffiliates。OracleisaregisteredtrademarkofOracleCorporationandoritsaffiliates。Othernamesmaybetrademarksoftheirrespectiveowners。Typehelp;orhforhelp。Typectoclearthecurrentinputstatement。mysqlselectversion();version()8。0。271rowinset(0。00sec)mysql