前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >腾讯云CentOS 7环境下安装MySQL数据库并初始化

腾讯云CentOS 7环境下安装MySQL数据库并初始化

原创
作者头像
TCS-F
修改2022-03-28 09:16:21
2.8K0
修改2022-03-28 09:16:21
举报
PS:近期因海外电商业务系统搭建,为方便配置MySQL数据库,实现业务高可用,快速构建自己的MySQL应用网站系统,
特研究了下MySQL数据库的配置初始化安装;特分享给大家

LINUX云服务器环境,8核16G-S5,500G-极速SSD盘;香港云服务器

步骤一:更新YUM源

运行以下命令添加epel源。
yum install \ https://repo.ius.io/ius-release-el7.rpm \ https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

步骤二:安装MySQL

运行以下命令更新YUM源。
rpm -Uvh  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

运行以下命令安装MySQL。 说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。

您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。

yum -y install mysql-community-server

运行以下命令查看MySQL版本号。

mysql -V
返回结果如下所示,表示MySQL安装成功。
mysql  Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using  EditLine wrapper
  1. 运行以下命令启动MySQL。
  systemctl start mysqld

2. 依次运行以下命令设置开机启动MySQL。

systemctl enable mysqld systemctl daemon-reload

步骤三:初始化配置MySQL数据库

运行以下命令查看/var/log/mysqld.log文件,获取并记录root用户的初始密码。

grep 'temporary password' /var/log/mysqld.log

命令行返回结果如下,其中ARQTRy3+n8*W为MySQL的初始密码。在下一步重置root用户密码时,会使用该初始密码。

2022-11-10T07:01:26.595215Z 1 [Note] A temporary password is generated for root@localhost: ARQTRy3+n8*W

运行以下命令配置MySQL的安全性。

mysql_secure_installation

输入MySQL的初始密码。 说明 在输入密码时,系统为了最大限度的保证数据安全,命令行将不做任何回显。您只需要输入正确的密码信息,然后按Enter键即可。

Securing the MySQL server deployment.  Enter password for user root: #输入上一步获取的root用户初始密码

为MySQL设置新密码。

The existing password for the user account root has expired. Please set a new password.  
New password: #输入新密码。长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号包含()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/  

Re-enter new password: #确认新密码。 
The 'validate_password' plugin is installed on the server. 
The subsequent steps will run with the existing configuration 
of the plugin. Using existing password for root. 
Estimated strength of the password: 100#返回结果包含您设置的密码强度。 
Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #您需要输入Y以确认使用新密码。#新密码设置完成后,需要再次验证新密码。 
New password:#再次输入新密码。  Re-enter new password:#再次确认新密码。 
Estimated strength of the password: 100 Do you wish to continuewith the password provided?(Press y|Y for Yes, any other key for No) :Y #您需要输入Y,再次确认使用新密码。

输入Y删除匿名用户。

Removeanonymoususers?(Pressy|YforYes,anyotherkeyforNo):Y
Success.

输入Y禁止使用root用户远程登录MySQL

Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):Y
Success.
Disallowrootloginremotely?(Pressy|YforYes,anyotherkeyforNo):Y Success.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :Y  
- Dropping test database... Success.   
- Removing privileges on test database... Success.

输入Y重新加载授权表。

Reloadprivilegetablesnow?(Pressy|YforYes,anyotherkeyforNo):Y
Success.All done!

腾讯云全新MySQL数据库上线,性能强劲,功能完备,支持千万级并发IOPS,新春活动,企业数字最经济实惠>>>>>>

腾讯云MySQL数据库专场:传送前往:https://cloud.tencent.com/act/cps/redirect?redirect=3563

推荐阅读:

  • 使用云数据库 MySQL 提高业务负载能力:https://cloud.tencent.com/act/cps/redirect?redirect=35711
  • 通过 Python 语言使用 MySQL API:https://cloud.tencent.com/act/cps/redirect?redirect=35710
  • 构建 LAMP 堆栈 Web 应用程序:https://cloud.tencent.com/act/cps/redirect?redirect=3570
  • MySQL数据库读写分离和一主多从应用场景:https://cloud.tencent.com/act/cps/redirect?redirect=1135
  • 【迪B课堂】如何正确的选择云数据库?https://cloud.tencent.com/act/cps/redirect?redirect=8
  • 腾讯云数据库回档解决方案https://cloud.tencent.com/act/cps/redirect?redirect=10
  • 基于腾讯云CVM搭建Hadoop集群并做数据迁移:https://cloud.tencent.com/act/cps/redirect?redirect=12
  • 【腾讯云CDB】源码分析·MySQL5.7中MDL实现分析:https://cloud.tencent.com/act/cps/redirect?redirect=17
  • 【腾讯云CDB】如何快速删除InnoDB中的大表:https://cloud.tencent.com/act/cps/redirect?redirect=18
  • 腾讯云MySQL数据库迁移过程中使用pt-table-checksum做数据一致性校验:https://cloud.tencent.com/act/cps/redirect?redirect=19

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 步骤一:更新YUM源
  • 步骤二:安装MySQL
  • 步骤三:初始化配置MySQL数据库
    • 推荐阅读:
    相关产品与服务
    云数据库 SQL Server
    腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档