# 2 安裝和更新 MySQL
本章描述了如何獲得和安裝 MySQL. 以下是過程的摘要, 后面的章節提供了詳細信息. 如果你計劃升級現有版本的 MySQL 為較新版本, 而不是第一次安裝, 參閱 [Section 2.11, “升級 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/upgrading.html), 獲取有關升級過程以及升級前應考慮的問題的相關信息.
如果你有興趣從另外的數據庫系統中遷移到 MySQL, 參閱 [A.8, “MySQL 8.0 常見問題解答: 遷移](https://dev.mysql.com/doc/refman/8.0/en/faqs-migration.html), 那里包含了一些常見遷移問題的答案.
安裝 MySQL 通常遵循以下步驟:
1. ***確定 MySQL 是否在你的平臺上運行并支持.***
請注意, 并不是所有的平臺都適合運行 MySQL, 并且并非所有運行 MySQL 的平臺都得到 Oracle Corporation 的官方支持. 有關官方支持平臺的信息, 請訪問 MySQL 站點的 https://www.mysql.com/support/supportedplatforms/database.html.
2. ***選擇要安裝的發行包.***
MySQL 有幾個版本可用, 大多數都有幾種分發格式. You can choose from pre-packaged distributions containing binary (precompiled) programs or source code. 如果有疑問, 請使用二進制發行包. Oracle 還為那些想要查看最新開發和測試新代碼的人提供了對 MySQL 源代碼的訪問. To determine which version and type of distribution you should use, see [Section 2.1.1, “Which MySQL Version and Distribution to Install”](https://dev.mysql.com/doc/refman/8.0/en/which-version.html).
3. ***下載要安裝的發行包.***
有關說明, 參閱 [2.1.2, “如何獲得 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/getting-mysql.html). 驗證發行包的完整性, use the instructions in [Section 2.1.3, “Verifying Package Integrity Using MD5 Checksums or GnuPG”](https://dev.mysql.com/doc/refman/8.0/en/verifying-package-integrity.html).
4. ***安裝發行包.***
從二進制發行包中安裝 MySQL, use the instructions in [Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”](https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html).
To install MySQL from a source distribution or from the current development source tree, use the instructions in [Section 2.9, “Installing MySQL from Source”](https://dev.mysql.com/doc/refman/8.0/en/source-installation.html).
5. ***執行任何安裝后的設置.***
安裝 MySQL 之后, 確定 MySQL 服務器正常運行的信息, 參閱 [2.10, “安裝后設置和測試”](https://dev.mysql.com/doc/refman/8.0/en/postinstallation.html). 另請參閱 [Section 2.10.4, “安全的初始化 MySQL 賬戶”](https://dev.mysql.com/doc/refman/8.0/en/default-privileges.html)提供的信息. 本章介紹了如何安全的初始化 MySQL `root` 用戶賬戶, 在你指派一個前, *沒有密碼*. The section applies whether you install MySQL using a binary or source distribution.
6. 如果你想運行 MySQL benchmark 腳本, 必須提供對 MySQL 的 Perl 支持. 參閱 [2.13, “Perl 安裝說明”](https://dev.mysql.com/doc/refman/8.0/en/perl-support.html).
Instructions for installing MySQL on different platforms and environments is available on a platform by platform basis:
- ***Unix, Linux, FreeBSD***
For instructions on installing MySQL on most Linux and Unix platforms using a generic binary (for example, a .tar.gz package), see [Section 2.2, “Installing MySQL on Unix/Linux Using Generic Binaries”](https://dev.mysql.com/doc/refman/8.0/en/binary-installation.html).
有關從源代碼發行版或者源代碼存儲庫構建 MySQL 的信息, 參閱 [Section 2.9, “從源代碼安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/source-installation.html)
對于指定平臺的安裝, 配置和從源文件編譯的幫助, 請參閱對應平臺章節:
- Linux, 包括發行版特定方法的說明, 參閱 [2.5, “在 Linux” 上安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/linux-installation.html).
- IBM AIX, 參閱 [2.7, “在 Solaris 上安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/solaris-installation.html).
- FreeBSD, 參閱 [2.8, “在 FreeBSD 上安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/freebsd-installation.html).
- ***Microsoft Windows***
有關在 Microsoft Windows 安裝 MySQL 的說明, 使用 MySQL 安裝程序或者二進制壓縮包, 參閱 [2.3, “在 Microsoft Windows 上安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/windows-installation.html).
有關管理 MySQL 實例的說明, 參閱 [2.3.4, “MySQL Notifier”](https://dev.mysql.com/doc/refman/8.0/en/windows-notifier.html).
有關使用 Microsoft Visual Studio 從源代碼構建 MySQL 的詳細信息和說明, 參閱 [Section 2.9, “從源碼安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/source-installation.html).
- ***OS X***
對于 OS X 上安裝, 包含使用二進制包和原生 PKG 格式兩種, 參閱 [Section 2.4, “在 macOS 上安裝 MySQL”](https://dev.mysql.com/doc/refman/8.0/en/osx-installation.html).
對于使用 OS X Launch Daemon 自動啟動和停止的信息, 參閱 [Section 2.4.3, “安裝和使用 MySQL Launch Daemon”](https://dev.mysql.com/doc/refman/8.0/en/osx-installation-launchd.html).
有關 MySQL 偏好面板的信息, 參閱 [Section 2.4.4, “安裝和使用 MySQL 偏好面板”](https://dev.mysql.com/doc/refman/8.0/en/osx-installation-prefpane.html).
- 簡介
- 前言和法律條款
- 安裝和更新 MySQL
- 在 Linux 上安裝 MySQL
- 在 Linux 上使用 APT 庫安裝 MySQL
- 在 Linux 上使用 Docker 部署 MySQL
- 使用 Docker 部署 MySQL 服務器的基本步驟
- 使用 Docker 部署 MySQL 服務器的更多主題
- 教程
- 連接到服務器和從服務器斷開
- 輸入查詢
- 創建和使用數據庫
- 創建和選擇數據庫
- 創建表
- 將數據加載到表中
- 從表中檢索數據
- 選擇所有數據
- 選擇特定行
- 選擇指定列
- 行排序
- 日期計算
- 處理 NULL 值
- 模式匹配
- 計算行數
- 使用多個表
- 獲取數據庫和表的信息
- 在批處理模式使用 mysql
- 常見查詢示例
- 列的最大值
- 包含某一行最大值的記錄
- 每組中列的最大值
- 擁有某個字段的組間最大值的行
- 使用用戶自定義變量
- 使用外鍵
- 兩個鍵上搜索
- 計算每日訪問量
- 使用 AUTO_INCREMENT
- 在 Apache 中使用 MySQL
- MySQL 程序
- MySQL 客戶端程序
- mysql — MySQL 命令行客戶端
- 優化
- 優化概述
- 優化 SQL 語句
- 優化和索引
- 優化數據庫結構
- 優化 InnoDB 表
- 優化 MyISAM 表
- 優化 MEMORY 表
- 理解查詢執行計劃
- 控制查詢優化器
- 緩沖和緩存
- 優化鎖操作
- 優化 MySQL 服務器
- 測量性能 (Benchmarking)
- 檢查線程信息