CentOS安装MySql

本文档详细介绍了如何通过Yum仓库进行MySQL的初次安装、启动、安全配置及更新操作,并提供了替换第三方MySQL发行版的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Steps for a Fresh Installation of MySQL

Note

The following instructions assume that no versions of MySQL (whether distributed by Oracle or other parties) have already been installed on your system; if that is not the case, follow the instructions given in Replacing a Native Third-Party Distribution of MySQL or Replacing MySQL Installed by a Direct RPM Download instead.

  1. Adding the MySQL Yum Repository

    First, add the MySQL Yum repository to your system's repository list. Follow these steps:

    1. Go to the download page for MySQL Yum repository at downloads/repo/yum/.

    2. Select and download the release package for your platform.

    3. Install the downloaded release package with the following command, replacing platform-and-version-specific-package-name with the name of the downloaded package:

      shell> sudo rpm -Uvh platform-and-version-specific-package-name.rpm
      

      For example, for version n of the package for EL6-based systems, the command is:

      shell> sudo rpm -Uvh mysql-community-release-el6-n.noarch.rpm  
      

    Warning

    Once the release package is installed on your system, any system-wide update by the yum update command will automatically upgrade MySQL packages on your system and also replace any native third-party packages, if Yum finds replacements for them in the MySQL Yum repository. See Upgrading MySQL with the MySQL Yum Repository and Replacing a Native Third-Party Distribution of MySQL for details.

  2. Selecting a Release Series

    Note

    When using the MySQL Yum repository, the latest GA release of MySQL is selected for installation by default. If this is what you want, you can skip to the next step, Installing MySQL with Yum.

    Within the MySQL Yum repository, different release series of the MySQL Community Server are hosted in different subrepositories. The subrepository for the latest GA series (currently 5.6) is enabled by default, and the subrepositories for all other series (for example, the 5.7 series, currently still in developer milestone release (DMR) status) are disabled by default. Use this command to see all the subrepositories in the MySQL Yum repository, and see which of them are enabled or disabled:

    shell> yum repolist all | grep mysql
    

    To install the latest release from the latest GA series, no configuration is needed. To install the latest release from a specific series other than the latest GA series, disable the subrepository for the latest GA series and enable the subrepository for the specific series before running the installation command. You can do that by editing manually the /etc/yum.repos.d/mysql-community.repo file. This is a typical entry for a release series' subrepository in the file:

    # Enable to use MySQL 5.6
    [mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 

    Find the entry for the subrepository you want to configure, and edit the enabled option. Specify enabled=0 to disable a subrepository, or enabled=1 to enable a subrepository. For example, to install the latest 5.7 DMR, make sure you have enabled=0 for the above subrepository entry for MySQL 5.6, and have enabled=1 for the entry for the 5.7 series:

    # Note: MySQL 5.7 is currently in development. For use at your own risk.
    # Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
    [mysql57-community-dmr]
    name=MySQL 5.7 Community Server Development Milestone Release
    baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
    

    You should only enable subrepository for one release series at any time. When subrepositories for more than one release series are enabled, the latest series will be used by Yum.

    Verify that the correct subrepositories have been enabled and disabled by running the following command and checking its output:

    shell> yum repolist enabled | grep mysql
    

  3. Installing MySQL with Yum

    Install MySQL by the following command:

    shell> sudo yum install mysql-community-server 
    

    This installs the package for the MySQL server, as well as other required packages.

  4. Starting and Stopping the MySQL Server

    Start the MySQL server with the following command:

    shell> sudo service mysqld start

    You can check the status of the MySQL server with the following command:

    shell> sudo service mysqld status

    Stop the MySQL server with the following command:

    shell> sudo service mysqld stop

  5. Securing the MySQL Installation

    The program mysql_secure_installation allows you to perform important operations like setting the root password, removing anonymous users, and so on. Always run it to secure your MySQL installation:

    shell> mysql_secure_installation

    It is important to remember the root password you set. See mysql_secure_installation — Improve MySQL Installation Security for details.

Note

For EL7-based platforms: See Compatibility Information for EL7-based platforms.

Installing Additional MySQL Products and Components

You can use Yum to install and manage individual components of MySQL. Some of these components are hosted in subrepositories of the MySQL Yum repository. Use the following command to list the packages for all the MySQL components available for your platform from all subrepositories in the MySQL Yum repository:

shell> yum --disablerepo=\* --enablerepo='mysql*-community*' list available

Install any packages of your choice with the following command, replacing package-name with name of the package:

shell> sudo yum install package-name 

For example, to install MySQL Workbench:

shell> sudo yum install mysql-workbench-community

Upgrading MySQL with the MySQL Yum Repository

Note
  • Before performing any update to MySQL, follow carefully the instructions in Upgrading MySQL. Among other instructions discussed there, it is especially important to back up your database before the update.

Use the MySQL Yum repository to perform an in-place update (that is, replacing the old version and then running the new version off the old data files) for your MySQL installation by following these steps (they assume you have installed MySQL with the MySQL Yum repository; if that is not the case, following the instructions in Replacing a Native Third-Party Distribution of MySQL or Replacing MySQL Installed by a Direct RPM Download instead):

  1. Selecting a Target Series

    By default, the MySQL Yum repository updates MySQL to the latest version in the release series you have chosen during installation (see Selecting a Release Series for details), which means, for example, a 5.6.x installation will NOT be updated to a 5.7.x release automatically. To update to another release series, you need to first disable the subrepository for the series that has been selected (by default, or by yourself) and enable the subrepository for your target series. To do that, follow the steps explained in Selecting a Release Series for editing the subrepository entries in the/etc/yum.repos.d/mysql-community.repo file.

    As a general rule, to upgrade from one release series to another, go to the next series rather than skipping a series. For example, if you are currently running MySQL 5.5 and wish to upgrade to 5.7, upgrade to MySQL 5.6 first before upgrading to 5.7.

    Important

    For important information about upgrading from MySQL 5.6 to 5.7, see Upgrading from MySQL 5.6 to 5.7.

  2. Upgrading MySQL

    Upgrade MySQL and its components by the following command:

    shell> sudo yum update mysql-server

    Alternatively, you can update MySQL by telling Yum to update everything on your system (this might take considerably more time):

    shell> sudo yum update

  3. Restarting MySQL

    The MySQL server always restarts after an update by Yum. Once the server restarts, run mysql_upgrade to check and possibly resolve any incompatibilities between the old data and the upgraded software.mysql_upgrade also performs other functions; see mysql_upgrade — Check and Upgrade MySQL Tables for details.

You can also update only a specific component. Use the following command to list all the installed packages for the MySQL components:

shell> sudo yum list installed | grep "^mysql"

After identifying the package name of the component of your choice, update the package with the following command, replacing package-name with the name of the package:

shell> sudo yum update package-name

Replacing a Native Third-Party Distribution of MySQL

To replace third-party distributions of MySQL that were installed from the supported Linux platforms' native software repositories with the latest GA version of MySQL from the MySQL Yum repository, follow these steps:

  1. Backing Up Your Database

    To avoid loss of data, always back up your database before trying to replace your MySQL installation using the MySQL Yum repository. See Backup and Recovery on how to back up your database.

  2. Adding the MySQL Yum Repository

    Add the MySQL Yum repository to your system's repository list by following the instructions given in Adding the MySQL Yum Repository.

  3. Replacing the Native Third-Party Distribution by a Yum Update

    By design, the MySQL Yum repository will replace your native, third-party MySQL when you perform a yum update command on the system, or a yum update mysql-server.

After updating MySQL using the Yum repository, applications compiled with older versions of the shared client libraries should continue to work. However, if you want to recompile applications and dynamically link them with the updated libraries, see Upgrading to the Shared Client Libraries for some special considerations.

Notes

Replacing MySQL Installed by a Direct RPM Download

RPMs for installing MySQL Community Server and its components can be downloaded from MySQL either from the MySQL Developer Zone's MySQL Download page or from the MySQL Yum repository. The RPMs from the two sources are different, and they install and configure MySQL in different ways.

If you have installed MySQL with the MySQL Developer Zone's RPMs and now want to replace the installation using the RPM from the MySQL Yum repository, follow these steps:

  1. Back up your database to avoid data loss. See Backup and Recovery on how to do that.

  2. Follow the steps given for Adding the MySQL Yum Repository.

  3. Follow the steps given for Selecting a Release Series.

  4. Get a list of the installed MySQL packages:

    shell> rpm -qa --qf '%{name}\n' | grep MySQL
    MySQL-client
    MySQL-test
    MySQL-embedded
    MySQL-shared
    MySQL-shared-compat
    MySQL-server
    MySQL-devel
    

  5. Uninstall those MySQL packages you have found. For the preceding list:

    shell> sudo yum remove MySQL-client MySQL-test MySQL-embedded \
     MySQL-shared MySQL-shared-compat MySQL-server MySQL-devel
    

  6. Install the equivalent packages (or just the ones you need) from the MySQL Yum repository. For our preceding example:

    shell sudo yum install mysql-community-client mysql-community-test \
     mysql-community-embedded mysql-community-common mysql-community-libs \
     mysql-community-libs-compat mysql-community-server mysql-community-devel
from: http://dev.mysql.com/doc/mysql-yum-repo-quick-guide/en/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值