当前位置: 首页 > MySQL数据库

Ubuntu下MySQL如何安装

时间:2026-01-26 14:21:28

1. 安装
sudoapt-getupdatesudoapt-getinstall

2. 数据库初始化
sudo

交互如下:
SecuringtheMySQLserverdeployment.ConnectingtoMySQLusingablankpassword.VALIDATEPASSWORDPLUGINcanbeusedtotestpasswordsandimprovesecurity.Itchecksthestrengthofpasswordandallowstheuserstosetonlythosepasswordswhicharesecureenough.WouldyouliketosetupVALIDATEPASSWORDplugin?Pressy|YforYes,anyotherkeyforNo:yTherearethreelevelsofpasswordvalidationpolicy:LOWLength>=8MEDIUMLength>=8,numeric,mixedcase,andspecialcharactersSTRONGLength>=8,numeric,mixedcase,specialcharactersanddictionaryfilePleaseenter0=LOW,1=MEDIUMand2=STRONG:2<=====注意这里一定要选2,STRONGPleasesetthepasswordforroothere.Newpassword:Re-enternewpassword:Estimatedstrengthofthepassword:100Doyouwishtocontinuewiththepasswordprovided?(Pressy|YforYes,anyotherkeyforNo):yBydefault,aMySQLinstallationhasananonymoususer,allowinganyonetologintoMySQLwithouthavingtohaveauseraccountcreatedforthem.Thisisintendedonlyfortesting,andtomaketheinstallationgoabitsmoother.Youshouldremovethembeforemovingintoaproductionenvironment.Removeanonymoususers?(Pressy|YforYes,anyotherkeyforNo):ySuccess.Normally,rootshouldonlybeallowedtoconnectfrom'localhost'.Thisensuresthatsomeonecannotguessattherootpasswordfromthenetwork.Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):ySuccess.Bydefault,MySQLcomeswithadatabasenamed'test'thatanyonecanaccess.Thisisalsointendedonlyfortesting,andshouldberemovedbeforemovingintoaproductionenvironment.Removetestdatabaseandaccesstoit?(Pressy|YforYes,anyotherkeyforNo):y-Droppingtestdatabase...Success.-Removingprivilegesontestdatabase...Success.Reloadingtheprivilegetableswillensurethatallchangesmadesofarwilltakeeffectimmediately.Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):ySuccess.Alldone!

3. 不使用sudo访问MySQL($ mysql -uroot -p)要求对MySQL设置最高密码强度
Pleaseenter0=LOW,1=MEDIUMand2=

4. 启动MySQL
sudosystemctlstartmysql.servicesudosystemctlenablemysql.servicesudo

5. 权限设定(可选)
mysql>usemysql;mysql>selectUser,Host,pluginfromuser;+------------------+-----------+-----------------------+|User|Host|plugin|+------------------+-----------+-----------------------+|root|localhost|auth_socket<--这里||mysql.session|localhost|mysql_native_password||mysql.sys|localhost|mysql_native_password||debian-sys-maint|localhost|mysql_native_password|+------------------+-----------+-----------------------+mysql>updateusersetplugin='mysql_native_password'whereUser='root'andHost='localhost';mysql>GRANTALLPRIVILEGESON*.*TO'root'@'localhost';mysql>flushprivileges;

6. 修改字符集为UTF-8
mysql>showvariableslike'char%';mysql>showvariableslike'collation%';sudovim/etc/mysql/conf.d/mysql.cnf[mysql]default-character-set=utf8sudovim/etc/mysql/mysql.conf.d/mysqld.cnf[mysqld]collation-server=utf8_general_cicharacter-set-server=utf8sudo

7. 查看运行状态
sudosystemctlstatusmysql.servicesudolsof-i:3306netstat-ntpl|grep

上一篇:mysql中生日日期怎么表示
下一篇:MySQL左连接、右连接、内连接与Hash连接怎么实现
Ubuntu mysql

  • 英特尔与 Vertiv 合作开发液冷 AI 处理器
  • 英特尔第五代 Xeon CPU 来了:详细信息和行业反应
  • 由于云计算放缓引发扩张担忧,甲骨文股价暴跌
  • Web开发状况报告详细介绍可组合架构的优点
  • 如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳
  • 美光在数据中心需求增长后给出了强有力的预测
  • 2027服务器市场价值将接近1960亿美元
  • 生成式人工智能的下一步是什么?
  • 分享在外部存储上安装Ubuntu的5种方法技巧
  • 全球数据中心发展的关键考虑因素
  • 英特尔与 Vertiv 合作开发液冷 AI 处理器

    英特尔第五代 Xeon CPU 来了:详细信息和行业反应

    由于云计算放缓引发扩张担忧,甲骨文股价暴跌

    Web开发状况报告详细介绍可组合架构的优点

    如何使用 PowerShell 的 Get-Date Cmdlet 创建时间戳

    美光在数据中心需求增长后给出了强有力的预测

    2027服务器市场价值将接近1960亿美元

    生成式人工智能的下一步是什么?

    分享在外部存储上安装Ubuntu的5种方法技巧

    全球数据中心发展的关键考虑因素