Linux System Environment
[root@master01 ~]# cat /etc/redhat-release #==》系统版本
CentOS Linux release 7.5.1804 (Core)
[root@master01 ~]# uname –r #==》系统内核
3.10.0-862.el7.x86_64
[root@master01 ~]# uname -m #==》系统位数
x86_64
[root@master01 ~]#echo $LANG #==》系统字符集
en_US.UTF-8
[root@master01 ~]# mysql –version #==》MySQL版本
mysql Ver 14.14 Distrib 5.7.27, for linux-glibc2.12 (x86_64) using EditLine wrapper
一、配置阿里云yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache
二、yum安装所需的依赖包
yum -y install ncurses-devel libaio-devel gcc gcc++ wget
三、安装CMake编译工具及下载boost源码包并解压
标注:CMake是用来编译MySQL(以前./configure编译工具在MySQL 5.5以后的版本使用CMake编译工具替代),boost软件包是MySQL 5.7版本编译所需要指定的库(只需要解压到自定义的目录,然后在MySQL 5.7 CMake编译时在参数-DWITH_BOOST=指定自定义的目录即可 ),boost官网: https://www.boost.org/
#==》源码安装CMake工具:
[root@master01 ~]# mkdir -p /home/oldboy/tools/
[root@master01 ~]# cd /home/oldboy/tools/
[root@master01 tools]# wget https://cmake.org/files/v3.0/cmake-3.0.0.tar.gz
[root@master01 tools]# tar xf cmake-3.0.0.tar.gz
[root@master01 tools]# cd cmake-3.0.0
[root@master01 cmake-3.0.0]# ./configure
[root@master01 cmake-3.0.0]# gmake
[root@master01 cmake-3.0.0]# gmake install
#==》下载并解压boost工具到指定路径,不用安装
[root@master01 ~]# mkdir /application
[root@master01 ~]# cd /application/
[root@master01 boost]# wget https://dl.bintray.com/boostorg/release/1.74.0/source/boost_1_74_0.tar.gz
[root@master01 boost]# tar xf boost_1_74_0.tar.gz
[root@master01 application]# mv boost_1_74_0 boost
四、创建myql虚拟用户
[root@master01 ~]# useradd -s /sbin/nologin -M mysql
[root@master01 ~]# id mysql
uid=1002(mysql) gid=1002(mysql) groups=1002(mysql)
五、下载并编译安装MySQL 5.7.27
标注:MySQL源码安装包
[root@master01 tools]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27.tar.gz
[root@master01 tools]# tar xf mysql-5.7.27.tar.gz
[root@master01 tools]# cd mysql-5.7.27
[root@master01 tools]#
cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql-5.7.27 \
-DMYSQL_DATADIR=/application/mysql-5.7.27/data \
-DMYSQL_UNIX_ADDR=/application/mysql-5.7.27/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=gbk,gb2312,utf8,ascii \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FAST_MUTEXES=1 \
-DWITH_ZLIB=bundled \
-DWITH_BOOST=/application/boost \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_READLINE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_DEBUG=0
[root@master01 mysql-5.7.27]# make
[root@master01 mysql-5.7.27]# make install
[root@master01 mysql-5.7.27]# ln -s /application/mysql-5.7.27/ /application/mysql
六、配置MySQL环境变量PATH
[root@master01 ~]# echo 'export PATH=/application/mysql/bin:$PATH' >> /etc/profile
[root@master01 ~]# tail -1 /etc/profile
export PATH=/application/mysql/bin:$PATH
[root@master01 ~]# source /etc/profile
[root@master01 ~]# echo $PATH
/application/mysql/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
七、MySQL数据目录授权mysql虚拟用户及用户组
[root@master01 ~]# mkdir -p /application/mysql/data
[root@master01 ~]# chown -R mysql.mysql /application/mysql/data/
[root@master01 ~]# ls -ld /application/mysql/data/
drwxr-xr-x 2 mysql mysql 6 Aug 24 22:29 /application/mysql/data/
八、编辑MySQL数据库主配置文件/etc/my.cnf
标注:MySQL 5.7.27版本原码安装包没有自带的my.cnf配置文件,需要手动配置参数
[root@master01 ~]# vim /etc/my.cnf
[client]
port = 3306
socket = /application/mysql/data/mysql.sock
[mysql]
no-auto-rehash
[mysqld]
user = mysql
port = 3306
socket = /application/mysql/data/mysql.sock
basedir = /application/mysql
datadir = /application/mysql/data
server-id = 1
九、MySQL初始化
[root@master01 ~]# cd /application/mysql
#==》初始化MySQL数据库,初始化的信息里有记录MySQL数据库root的初始密码,记得保存
[root@master01 mysql]# ./bin/mysqld --initialize --user=mysql --basedir=/application/mysql/ --datadir=/application/mysql/data/
2019-08-24T14:40:39.946703Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-08-24T14:40:42.231308Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-08-24T14:40:42.509866Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-08-24T14:40:42.592678Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2637ffc3-c67d-11e9-b5d5-000c29aa0ed9.
2019-08-24T14:40:42.595555Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-08-24T14:40:42.598302Z 1 [Note] A temporary password is generated for root@localhost: L5Cw,7yN>2;_ #==》临时生成的MySQL用户root的登录密码
十、启动MySQL并设置开机自启动
标注:/application/mysql/bin/mysqld是MySQL程序目录下bin的mysqld命令
[root@master01 ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#==》启动MySQL服务
[root@master01 ~]# systemctl start mysqld.service
#==》设置MySQL服务开机自启动
[root@master01 ~]# systemctl enable mysqld.service
#==》查看MySQL服务状态
[root@master01 ~]# systemctl status mysqld.service
十一、登录MySQL数据库
[root@master01 ~]# mysql -uroot -p'L5Cw,7yN>2;_'
#==》第一次登录MySQL要求首先设置MySQL数据库密码才可以继续使用,否则会报如下错误
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql> set password=password("123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
网友评论