MySQL 官方源代码包编译安装 MySQL 服务

  1. 重新登录,清空防火墙规则,关闭 selinux,配置 eth0 网卡
[root@centos7 ~]# systemctl stop firewalld
[root@centos7 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

[root@centos7 ~]# iptables -F
[root@centos7 ~]# iptables -vnL
Chain INPUT (policy ACCEPT 30 packets, 2344 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 23 packets, 2308 bytes)
 pkts bytes target     prot opt in     out     source               destination   
[root@centos7 ~]# setenforce 0
[root@centos7 ~]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 
  1. 从官方网站下载 MySQL 的源代码包

源码包官方下载地址:https://dev.mysql.com/downloads/mysql/

[root@centos7 ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.46.tar.gz

  1. 创建 mysql 系统用户,安装编译 MySQL 所依赖的软件包
[root@centos7 ~]# useradd -r mysql -s /sbin/nologin
[root@centos7 ~]# id mysql 
uid=998(mysql) gid=996(mysql) groups=996(mysql)
[root@centos7 ~]# yum install epel-release -y 

#根据个人安装
[root@centos7 ~]# yum install bison bison-devel zlib-devel libcurl-devel libarchive-devel boost-devel gcc gcc-c++ cmake ncurses-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel -y
  1. 解压 MySQL 软件包,编译选项配置
[root@centos7 ~]# tar xf mysql-5.6.46.tar.gz 
[root@centos7 ~]# cd mysql-5.6.46

[root@centos7 mysql-5.6.46]# ll
total 472
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 BUILD
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 client
drwxr-xr-x.  4 7161 31415   4096 Sep 27 15:12 cmake
-rw-r--r--.  1 7161 31415  24653 Sep 27 15:04 CMakeLists.txt
drwxr-xr-x.  3 7161 31415     21 Sep 27 15:12 cmd-line-utils
-rw-r--r--.  1 7161 31415  20248 Sep 27 15:04 config.h.cmake
-rw-r--r--.  1 7161 31415  41346 Sep 27 15:04 configure.cmake
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 dbug
drwxr-xr-x.  2 7161 31415     80 Sep 27 15:12 Docs
-rw-r--r--.  1 7161 31415  65958 Sep 27 15:04 Doxyfile-perfschema
drwxr-xr-x.  3 7161 31415    216 Sep 27 15:12 extra
drwxr-xr-x.  4 7161 31415   4096 Sep 27 15:12 include
-rw-r--r--.  1 7161 31415    333 Sep 27 15:04 INSTALL
drwxr-xr-x.  3 7161 31415    224 Sep 27 15:12 libmysql
drwxr-xr-x.  3 7161 31415    204 Sep 27 15:12 libmysqld
drwxr-xr-x.  2 7161 31415    221 Sep 27 15:12 libservices
-rw-r--r--.  1 7161 31415 221739 Sep 27 15:04 LICENSE
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:13 man
drwxr-xr-x. 10 7161 31415   4096 Sep 27 15:12 mysql-test
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 mysys
drwxr-xr-x.  2 7161 31415    259 Sep 27 15:12 mysys_ssl
drwxr-xr-x.  9 7161 31415    113 Sep 27 15:12 packaging
drwxr-xr-x. 11 7161 31415    187 Sep 27 15:12 plugin
-rw-r--r--.  1 7161 31415    587 Sep 27 15:04 README
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 regex
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:13 scripts
drwxr-xr-x.  2 7161 31415      6 Sep 27 15:12 source_downloads
drwxr-xr-x.  4 7161 31415  12288 Sep 27 15:13 sql
drwxr-xr-x.  5 7161 31415   4096 Sep 27 15:12 sql-bench
drwxr-xr-x.  2 7161 31415    155 Sep 27 15:12 sql-common
drwxr-xr-x. 13 7161 31415    169 Sep 27 15:12 storage
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 strings
drwxr-xr-x.  5 7161 31415   4096 Sep 27 15:13 support-files
drwxr-xr-x.  2 7161 31415   4096 Sep 27 15:12 tests
drwxr-xr-x.  5 7161 31415     70 Sep 27 15:12 unittest
-rw-r--r--.  1 7161 31415     88 Sep 27 15:04 VERSION
drwxr-xr-x.  3 7161 31415   4096 Sep 27 15:12 vio
drwxr-xr-x.  2 7161 31415     32 Sep 27 15:12 win
drwxr-xr-x. 11 7161 31415   4096 Sep 27 15:12 zlib


[root@centos7 mysql-5.6.46]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc/mysql  -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1  -DWITH_DEBUG=0  -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_LIBWRAP=0 -DENABLED_LOCAL_INFILE=1 -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci
  1. 编译与安装
[root@centos7 mysql-5.6.46]# make 
Scanning dependencies of target INFO_SRC
Scanning dependencies of target INFO_BIN
[  0%] Scanning dependencies of target abi_check
Generating common.h
[  0%] [  0%] Built target INFO_SRC
[  0%] Generating help.c
Built target INFO_BIN
Scanning dependencies of target event
Scanning dependencies of target event_core
[  0%] Generating help.h
[  0%] Generating vi.h
[  0%] [  0%] Building C object extra/libevent/CMakeFiles/event_core.dir/buffer.c.o
Building C object extra/libevent/CMakeFiles/event.dir/buffer.c.o
[  0%] [  1%] Built target abi_check
Generating emacs.h
Scanning dependencies of target event_extra
[  1%] Generating fcns.c
[  1%] Generating fcns.h
[  1%] Building C object extra/libevent/CMakeFiles/event_extra.dir/buffer.c.o
Scanning dependencies of target edit


.
.省略部分 make 输出信息........
.

[100%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/mysql.cc.o
[100%] Building CXX object libmysqld/examples/CMakeFiles/mysql_embedded.dir/__/__/client/readline.cc.o
Linking CXX executable mysql_embedded
Linking CXX executable mysqltest_embedded
[100%] [100%] Built target mysql_embedded
Built target mysqltest_embedded
Linking CXX executable mysql_client_test_embedded
[100%] Built target mysql_client_test_embedded


[root@centos7 mysql-5.6.46]# make install
[  0%] Built target INFO_BIN
[  0%] Built target INFO_SRC
[  0%] Built target abi_check
[  2%] Built target readline
[  3%] Built target pcre
[  3%] Built target pcreposix
[  3%] Built target pcregrep
[  3%] Built target pcretest

.
.省略部分 make install 输出信息........
.

-- Installing: /usr/local/mysql/sql-bench/test-insert
-- Installing: /usr/local/mysql/sql-bench/test-select
-- Installing: /usr/local/mysql/sql-bench/test-transactions
-- Installing: /usr/local/mysql/sql-bench/test-wisconsin

  1. 创建 MySQL 环境变量文件
[root@centos7 ~]# mkdir -pv /data/mysql
[root@centos7 ~]# cd /usr/local/mysql/
[root@centos7 mysql]# ll
total 248
drwxr-xr-x.  2 root root   4096 Nov 15 21:16 bin
drwxr-xr-x.  3 root root     18 Nov 15 21:16 data
drwxr-xr-x.  2 root root     55 Nov 15 21:16 docs
drwxr-xr-x.  3 root root   4096 Nov 15 21:16 include
drwxr-xr-x.  3 root root   4096 Nov 15 21:16 lib
-rw-r--r--.  1 root root 221739 Sep 27 15:04 LICENSE
drwxr-xr-x.  4 root root     30 Nov 15 21:16 man
drwxr-xr-x. 10 root root   4096 Nov 15 21:16 mysql-test
-rw-r--r--.  1 root root    587 Sep 27 15:04 README
drwxr-xr-x.  2 root root     30 Nov 15 21:16 scripts
drwxr-xr-x. 28 root root   4096 Nov 15 21:16 share
drwxr-xr-x.  4 root root   4096 Nov 15 21:16 sql-bench
drwxr-xr-x.  2 root root    136 Nov 15 21:16 support-files


[root@centos7 mysql]# yum install perl perl-Data-Dumper libaio -y 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.jdcloud.com
 * epel: hk.mirrors.thegigabit.com
 * extras: mirror.jdcloud.com
 * updates: mirror.jdcloud.com
Package 4:perl-5.16.3-294.el7_6.x86_64 already installed and latest version
Package perl-Data-Dumper-2.145-3.el7.x86_64 already installed and latest version
Package libaio-0.3.109-13.el7.x86_64 already installed and latest version
Nothing to do

[root@centos7 mysql]# ./scripts/mysql_install_db --datadir=/data/mysql --user=mysql
Installing MySQL system tables...2019-11-15 21:20:53 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-11-15 21:20:53 0 [Note] Ignoring --secure-file-priv value as server is running with --bootstrap.
.
.省略部分输出信息........
.
WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server


  1. 配置 MySQL 服务 PATH 变量文件
[root@centos7 ~]# vim /etc/profile.d/mysql5.6.sh
#!/bin/bash
export PATH=/usr/local/mysql/bin:$PATH

[root@centos7 ~]# source /etc/profile.d/mysql5.6.sh 
  1. 编辑 MySQL 的配置文件 my.cnf
[root@centos7 ~]# vim /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/data/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

  1. 复制启动脚本到 /etc/init.d 路径下, 添加服务为开启启动,然后启动服务
[root@centos7 ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@centos7 ~]# chkconfig --add mysqld
[root@centos7 ~]# chkconfig --list mysqld

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off


[root@centos7 ~]# service mysqld start
会出现以下错误
log-error set to '/var/log/mariadb/mariadb.log', however file don't exists.
解决方法如下
 mkdir /var/log/mariadb/
 touch /var/log/mariadb/mariadb.log
 chown -R mysql:mysql /var/log/mariadb/
service mysqld restart
[root@centos7 ~]# ss -ntl
LISTEN    0    80       :::3306       :::*    
  1. 执行安全初始化脚本,设置 root 密码为 123456,登录数据库
mysql_secure_installation 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we will need the current
password for the root user.  If you have just installed MySQL, and
you have not set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] 
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] 
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] 
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] 
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] 
 ... Success!

All done!  If you have completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up...

  1. 使用 mysql 命令连接 MySQL 服务
[root@centos7 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.6.46 Source distribution

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值