Chapter 2 Installing and Upgrading MySQL
Installation of MySQL generally follows the steps outlined here:
- Determine whether MySQL runs and is supported on your platform.
- Choose which distribution to install
- Download the distribution that you want to install.
- Install the distribution.
- Perform any necessary postinstallation setup
2.1 General Installation Guidance
我只看 2.1.2 和2.1.3
2.1.2 Which MySQL Version and Distribution to Install
mysql-8.0.1-dmr are interpreted as follows:
- 8 is the major version number.
- 0 is the minor version number.
- 1 is the version number within the release series. This is incremented for each new bugfix release.
Release names can also include a suffix to indicate the stability level of the release. - dmr indicates a development milestone release.
- rc indicates a Release Candidate.
- Absence of a suffix indicates a General Availability or Production release.
2.1.3 How to Get MySQL
2.9 Installing MySQL from Source
官网推荐 binary distribution, 但我的 glibc 是 2.28
2.9.1 Source Installation Methods
- Use a standard MySQL source distribution.
- Use a MySQL development tree.
2.9.2 Source Installation Prerequisites
- CMake, which is used as the build framework on all platforms.
apt-get install -y cmake
- A good make program.
- MySQL 8.0 source code permits use of C++14 features.
- GCC 5.3(Linux)
- The MySQL C API requires a C++ or C99 compiler to compile.
sudo apt-get install g++ , 进入下一个坑
我不知道 C99 compiler 是什么东西;希望 OS 自带吧, 并不自带,下载g++
- An SSL library is required for support of encrypted connections, entropy for random number generation, and other encryption-related operations.
sudo apt-get install libssl-dev
- The Boost C++ libraries are required to build MySQL.
mkdir -p /usr/local/boost
cd /usr/local/boost/
wget https://dl.bintray.com/boostorg/release/1.72.0/source/boost_1_72_0.tar.gz
tar -zxvf boost_1_72_0.tar.gz
sudo cmake .. -DWITH_BOOST=/usr/local/boost
- The ncurses library.
sudo apt-get install -y libncurses5-dev
- Sufficient free memory.
2.9.3 MySQL Layout for Source Installation
Installs files under /usr/local/mysql.
2.9.4 Installing MySQL Using a Standard Source Distribution
Perform Preconfiguration Setup
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
Obtain and Unpack the Distribution
tar zxvf mysql-version.tar.gz
Configure the Distribution
cd mysql-version
mkdir bld
cd bld
cmake ../mysql-src
To prevent old object files or configuration information from being used:
make clean
rm CMakeCache.txt
check the files in the CMakeFiles directory for useful information about the failure.
Build the Distribution
make
make VERBOSE=1
Install the Distribution
make install
make install DESTDIR="/opt/mysql"
make package
2.9.5 Installing MySQL Using a Development Source Tree
这是另外一种源码安装方式,我就不看了
2.9.6 Configuring SSL Library Support
CMake configures the distribution to use the installed OpenSSL library by default.
To compile using OpenSSL:
- Ensure that OpenSSL 1.0.1 or highter is installed on your system.
openssl version
- The WITH_SSL CMake option determines which SSL libraty to use for compiling MySQL. The default is -DWITH_SSL=system.
- Compile and install the distribution
To check whether a mysqld server supports encrypted connections:
show variables like 'have_ssl';
2.9.7 MySQL Source-Configuration Options
For information about options supported by CMake:
cmake . -LH
ccmake .
Configuration option description indicate the corresponding mysqld startup option.
The following section provide more information about CMake options
有点多,我不想看
2.9.8 Dealing with Problems Compiling MySQL
- To define which C and C++ compilers to use, you can define the CC and CXX environment variables.
CC=gcc
CXX=g++
export CC CXX
2.9.9 MySQL Configuration and Third-Party Tools
2.9.10 Generating MySQL Doxygen Documentation Content
PlantUML 我是第二次见, 我就下载了, 看样子很好用,看来又得看文档了
我没有去实践,比较遗憾
2.10 Postinstallation Setup and Testing
2.10.1 Initializing the Data Directory
Data Directory Initializtion Overview
- Change location to the top-level directory of your MySQL installation.
cd /usr/local/mysql
我的应该实在 bld 下面, 手册为什么是 /usr/local/mysql, 我也不知道,接着往下看
原来 手册没有错, 是我太菜鸡, 看了一下, 下面确实有bin目录, 可能是 make install 生成的
本人 java , 不懂c的编译过程
- The secure_file_priv system variable limits import and export operations to a specific directory.Create a directory whose location can be specified as the value of that variables:
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
- Use the server to initialize the data directory, including the mysql schema containing the initial MySQL grant tables that determine how users are permitted to connect to the server.
bin/mysqld --initialize --user=mysql
这儿会有一个临时密码
- Deploy the server with automatic support for secure connections.
bin/mysql_ssl_rsa_setup
- In the absence of any option files, the server starts with its default settings. To explicitly options that the MySQL server should use at startup, put them in /etc/my.cnf.
- To arrange for MySQL to start without manual intervention at system boot time.
下面会讲
- Creates time zone tables in the mysql schema but does not populate them.
第五章会讲 mysql 怎么读本地时区
Data Directory Initializtion Procedure
基本上和上一小节一样, 很不幸, 我没有把临时密码给保存下来。
我把data 目录删了,最好是重命名, 又重新执行一遍, password:(aCl.on,C9=o nTUUUNxuH5>i
- Use --initialize for “secure by default” installation, generate a temp password.
Use --initialize-insecure, no root password is generated.
Server Actions During Data Directory Initializtion
mysqld performs the following actions duriing the data directory installation sequence:
- The server checks for the existence of the data directory.
- Within the data directory, the server creates the mysql system schema ant its tables, including the data dictionary tables, grant tables, time zone tables, and server-side help tables.
- The server initializes the system tablespace and related data structures needed to manage InnoDB tables.
- Creates a ‘root’@‘localhost’ superuser account and other reserved accounts.
- Populates the server-side help tables used for the HELP statement.
- If the init_file system variable was given to name a file of SQL statements, executes the file.
- Exits.
Post-Initialization root Password Assignment
- Start the server.
后面会讲
- Connect to the server:
mysql -u root -p
- Use an alter user statement to assign a new root password:
alter user 'root'@'localhost' identified by 'root-password';
2.10.2 Starting the Server
2.10.2.1 Troubleshooting Problems Starting the MySQL Server
Start the MySQL server like this:
bin/mysqld_safe --user=mysql &
2.10.3 Testing the Server
Add the bin directory to your PATH environment variable setting.
export MYSQL_HOME=/usr/local/mysql
export PATH=$MYSQL_HOME/bin:$PATH
mysqladmin -uroot -p version
mysqladmin -uroot -p variables
Verify that you can shut down the server:
mysqladmin -uroot -p shutdown
Start again.
mysqld_safe --user=mysql &
我以为配置环境变量就行了, 原来还要配置 /etc/sudoers , 这个系统刚装的不太熟, 我设置一个符号链接, 然后sudo mysqld 就行
chmod 750 data
mysqlshow
mysqlshow mysql
mysql -e "select user, host, plugin from mysql.user" mysql
2.10.4 Securing the Initial MySQL Account
前面做过一次
2.10.5 Starting and Stopping MySQL Automatically
use mysqld_safe, mysql.server, mysqld
我感觉是我没有配置my.cnf的原因,我得去配置一个, 这部分没说什么。
原来是 /etc/sudoers 的问题
2.11 Updrading MySQL
剩下三小节我不看了