logo

【云服务器BCC】Mysql镜像配置

作者:chen1912092026.01.14 19:28浏览量:4

简介:本文介绍如何在百度智能云云服务器 BCC 中使用Mysql镜像及其基础配置方法。

概述

MySQL数据库服务是一种完全托管的数据库服务,用于部署云原生应用程序。

下载地址:http://mirrors.baidubce.com/mysql/

配置方法

1. 确认操作系统信息

查看操作系统版本

# centos/redhat 使用命令:
cat /etc/redhat-release 

# ubuntu/debian 使用命令:
cat /etc/issue

# 查看操作系统架构
uname -m

2. 配置YUM源(CentOS/RHEL)

2.1. Intel/AMD系统(x86)配置执行下框命令:

sudo tee /etc/yum.repos.d/mysql-baidu.repo << 'EOF'
[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-5.7-community-el7-x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-8.0-community-el7-x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

[mysql84-community]
name=MySQL 8.4 Community Server
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-8.4-community-el9-x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-connectors-community-el7-x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-tools-community-el7-x86_64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
EOF

2.2. ARM系统(arm64 或 aarch64)配置执行下框命令

# 创建MySQL YUM源配置文件
sudo tee /etc/yum.repos.d/mysql-baidu.repo << 'EOF'
[mysql80-community]
name=MySQL 8.0 Community Server
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-8.0-community-el7-aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023


[mysql84-community]
name=MySQL 8.0 Community Server
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-8.4-community-el9-aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023


[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-connectors-community-el7-aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023


[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://mirrors.baidubce.com/mysql/yum/mysql-tools-community-el7-aarch64/
enabled=1
gpgcheck=1
gpgkey=https://repo.mysql.com/RPM-GPG-KEY-mysql
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
       https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

EOF

2.3. 更新缓存

# 清理旧缓存
sudo yum clean all
# 更新缓存
sudo yum makecache
# 更新仓库列表
sudo yum update

更新仓库出现以下情况

[root@centos8 ~]# sudo yum update
Last metadata expiration check: 0:00:05 ago on Tue 13 Jan 2026 11:12:41 AM CST.
Error: 
 Problem: package perftest-4.5-1.el8.x86_64 requires libefa.so.1()(64bit), but none of the providers can be installed
  - package perftest-4.5-1.el8.x86_64 requires libefa.so.1(EFA_1.1)(64bit), but none of the providers can be installed
  - cannot install both libibverbs-35.0-1.el8.x86_64 and libibverbs-58mlnx43-1.58511.x86_64
  - cannot install the best update candidate for package perftest-4.5-0.18.gfcddfe0.58511.x86_64
  - problem with installed package libibverbs-58mlnx43-1.58511.x86_64
(try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

请执行

[root@centos8 ~]# sudo yum update --allowerasing --skip-broken --nobest
Last metadata expiration check: 0:07:03 ago on Tue 13 Jan 2026 11:12:41 AM CST.
Dependencies resolved.

 Problem: cannot install the best update candidate for package libibverbs-58mlnx43-1.58511.x86_64
  - cannot install both libibverbs-35.0-1.el8.x86_64 and libibverbs-58mlnx43-1.58511.x86_64
  - package perftest-4.5-1.el8.x86_64 requires libefa.so.1()(64bit), but none of the providers can be installed
  - package perftest-4.5-1.el8.x86_64 requires libefa.so.1(EFA_1.1)(64bit), but none of the providers can be installed
  - cannot install the best update candidate for package perftest-4.5-0.18.gfcddfe0.58511.x86_64
  - problem with installed package perftest-4.5-0.18.gfcddfe0.58511.x86_64
==========================================================================================================================================================================================================
 Package                                           Architecture                                  Version                                              Repository                                     Size
==========================================================================================================================================================================================================
Skipping packages with conflicts:
(add '--best' to command line to force their upgrade):
 libibverbs                                        x86_64                                        35.0-1.el8                                           baseos                                        335 k
Skipping packages with broken dependencies:
 perftest                                          x86_64                                        4.5-1.el8                                            baseos                                        248 k

Transaction Summary
==========================================================================================================================================================================================================
Skip  2 Packages

Nothing to do.
Complete!

2.4. 验证

查看可用的MySQL包

yum repolist enabled | grep mysql

显示配置的项目则成功

[root@centos8 ~]# yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community
mysql-tools-community      MySQL Tools Community
mysql57-community          MySQL 5.7 Community Server
mysql80-community          MySQL 8.0 Community Server
mysql84-community          MySQL 8.4 Community Server

3. 配置APT源(Ubuntu/Debian)

3.1. Ubuntu操作系统配置

3.1.1. 在下表中查看对应操作系统支持的Mysql版本

版本 版本代号 支持Mysql版本
Ubuntu 14.04 trusty MySQL 5.6/MySQL 5.7/MySQL 8.0/MySQL tools/connector-python-2.1
Ubuntu 16.04 xenial MySQL 5.6/MySQL 5.7/MySQL 8.0/MySQL tools
Ubuntu 18.04 bionic MySQL 5.7/MySQL 8.0/MySQL tools
Ubuntu 20.04 focal MySQL 8.0/MySQL tools
Ubuntu 22.04 jammy MySQL 8.0/MySQL 8.4 lts/MySQL tools
Ubuntu 24.04 noble MySQL 8.0/MySQL 8.4 lts/MySQL tools

3.1.2. 下框配置内容中包含当前百度源支持的所有Mysql版本

  1. 注释或删除不支持的MYSQL版本,只保留想要的MYSQL版本即可
  2. 将所有$version替换成当前操作系统的版本代号
  sudo tee /etc/apt/sources.list.d/mysql-baidu.list << 'EOF'

# MySQL 5.6
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ $version mysql-5.6

# MySQL 5.7
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ $version mysql-5.7

# MySQL 8.0
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ $version mysql-8.0

# MySQL 8.4 lts
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ $version mysql-8.4-lts

# MySQL tools
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ $version mysql-tools

EOF
Ubuntu 22.04示例:
sudo tee /etc/apt/sources.list.d/mysql-baidu.list << 'EOF'
# MySQL 8.0
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ jammy mysql-8.0

# MySQL 8.4 lts
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ jammy mysql-8.4-lts

# MySQL tools
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/ubuntu/ jammy mysql-tools

EOF

3.2. Debian操作系统配置执行下框命令

3.2.1. 在下表中查看对应操作系统支持的Mysql版本

版本 版本代号 支持Mysql版本
Debian 8 jessie MySQL 5.6/MySQL 5.7/MySQL 8.0/MySQL tools/connector-python-2.1
Debian 9 stretch MySQL 5.6/MySQL 5.7/MySQL 8.0/MySQL tools
Debian 10 buster MySQL 5.7/MySQL 8.0/MySQL tools
Debian 11 bullseye MySQL 8.0/MySQL tools
Debian 12 bookworm MySQL 8.0/MySQL 8.4 lts/MySQL tools
Debian 13 trixie MySQL 8.0/MySQL 8.4 lts/MySQL tools

3.2.2. 下框配置内容中包含当前百度源支持的所有Mysql版本

  1. 注释或删除不支持的MYSQL版本,只保留想要的MYSQL版本即可
  2. 将所有$version替换成当前操作系统的版本代号
sudo tee /etc/apt/sources.list.d/mysql-baidu.list << 'EOF'

# MySQL 5.6
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ $version mysql-5.6

# MySQL 5.7
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ $version mysql-5.7

# MySQL 8.0
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ $version mysql-8.0

# MySQL 8.4 lts
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ $version mysql-8.4-lts

# MySQL tools
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ bookworm mysql-tools
EOF
Debian 12示例:
sudo tee /etc/apt/sources.list.d/mysql-baidu.list << 'EOF'

# MySQL 8.0
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ bookworm mysql-8.0

# MySQL 8.4 lts
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ bookworm mysql-8.4-lts

# MySQL tools
deb [trusted=yes] http://mirrors.baidubce.com/mysql/apt/debian/ bookworm mysql-tools
EOF

3.3. 更新

ubuntu和debian更新仓库方式相同

# 清理旧缓存
apt-get clean
# 获取新仓库列表
apt-get update

3.4. 验证

ubuntu和debian验证仓库方式相同

# mysql仓库指向mirrors.baidubce.com表示配置成功

示例:
root@test:~# apt policy|grep mysql

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

 500 http://mirrors.baidubce.com/mysql/apt/ubuntu jammy/mysql-tools amd64 Packages
     release o=MySQL,n=jammy,l=MySQL,c=mysql-tools,b=amd64
 500 http://mirrors.baidubce.com/mysql/apt/ubuntu jammy/mysql-8.4-lts amd64 Packages
     release o=MySQL,n=jammy,l=MySQL,c=mysql-8.4-lts,b=amd64
 500 http://mirrors.baidubce.com/mysql/apt/ubuntu jammy/mysql-8.0 amd64 Packages
     release o=MySQL,n=jammy,l=MySQL,c=mysql-8.0,b=amd64

相关文章推荐

发表评论

活动