1.二进制安装
1)下载或者上传二进制包
[root@db01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.42-winx64.zip
#或者
[root@db01 ~]# rz mysql-5.6.42-winx64.zip
2)安装依赖
[root@db01 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf gcc-c++
3)解压安装包
[root@db01 ~]# tar xf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
4)移动并改名
[root@db01 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.42
5)做软连接
[root@db01 ~]# ln -s /usr/local/mysql-5.6.42 /usr/local/mysql
6)创建数据库用户
[root@db01 ~]# useradd mysql -s /sbin/nologin -M
7)拷贝配置文件和启动文件
[root@db01 ~]# cd /usr/local/mysql/support-files/
[root@db01 /usr/local/mysql/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@db01 /usr/local/mysql/support-files]# cp mysql.server /etc/init.d/mysqld
8)初始化数据库
#1.进入初始化文件目录
[root@db01 /usr/local/mysql/support-files]# cd ../scripts/
[root@db01 /usr/local/mysql/scripts]# ll
total 36
-rwxr-xr-x 1 7161 31415 34558 Sep 10 2018 mysql_install_db
#2.执行初始化
[root@db01 /usr/local/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
--user:指定用户
--basedir:mysql的安装目录
--datadir:mysql的数据目录
#3.初始化成功的标志
1)初始化过程有两个ok
2)数据目录下有库文件
[root@db01 /usr/local/mysql/scripts]# ll /usr/local/mysql/data/
total 110600
-rw-rw---- 1 mysql mysql 12582912 Oct 19 17:09 ibdata1
-rw-rw---- 1 mysql mysql 50331648 Oct 19 17:09 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648 Oct 19 17:09 ib_logfile1
drwx------ 2 mysql mysql 4096 Oct 19 17:09 mysql
drwx------ 2 mysql mysql 4096 Oct 19 17:09 performance_schema
drwxr-xr-x 2 mysql mysql 20 Oct 19 16:58 test
9)启动数据库
#二进制安装没有配置system管理
[root@db01 /usr/local/mysql/scripts]# systemctl start mysql
Failed to start mysql.service: Unit not found.
#使用启动脚本
[root@db01 /usr/local/mysql/scripts]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/usr/local/mysql/data/db01.err'.
SUCCESS!
10)验证数据库启动
#查看端口
[root@db01 /usr/local/mysql/scripts]# netstat -lntp | grep 3306
tcp6 0 0 :::3306 :::* LISTEN 7930/mysqld
#查看进程
[root@db01 /usr/local/mysql/scripts]# ps -ef | grep mysql
root 7822 1 0 17:14 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/db01.pid
mysql 7930 7822 0 17:14 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=db01.err --pid-file=/usr/local/mysql/data/db01.pid
root 7961 7441 0 17:15 pts/0 00:00:00 grep --color=auto mysql
#登录数据库
[root@db01 /usr/local/mysql/scripts]# /usr/local/mysql/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
11)配置system管理数据库启动
#1.配置system管理数据库文件
[root@db01 ~]# vim /usr/lib/systemd/system/mysqld.server
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
#2.重新加载system管理配置
[root@db01 ~]# systemctl daemon-reload
#3.使用system管理启动数据库
[root@db01 ~]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@db01 ~]# systemctl start mysqld
12)配置环境变量
#1.配置环境变量
[root@db01 ~]# vim /etc/profile.d/mysql.sh
export PATH=/usr/local/mysql/bin:$PATH
#2.重新加载环境变量
[root@db01 ~]# source /etc/profile
#3.测试mysql命令
[root@db01 ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.42 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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>
2.二进制安装(自定义安装目录)
1)上传包
[root@db03 ~]# rz
2)安装依赖
[root@db03 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf gcc-c++
3)解压
[root@db03 ~]# tar xf mysql-5.6.42-linux-glibc2.12-x86_64.tar.gz
4)创建自定义目录
[root@db03 ~]# mkdir /service
5)移动并改名
[root@db03 ~]# mv mysql-5.6.42-linux-glibc2.12-x86_64 /service/mysql-5.6.42
6)做软连接
[root@db03 ~]# ln -s /service/mysql-5.6.42 /service/mysql
7)创建用户
[root@db03 ~]# useradd mysql -s /sbin/nologin -M
8)拷贝启动文件和配置文件
[root@db03 ~]# cd /service/mysql/support-files/
[root@db03 /service/mysql/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db03 /service/mysql/support-files]# cp mysql.server /etc/init.d/mysqld
9)初始化
[root@db03 ~]# cd /service/mysql/scripts/
[root@db03 /service/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data
10)配置system管理启动MySQL
[root@db03 ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/service/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@db03 ~]# systemctl daemon-reload
11)启动数据库
#1.使用system启动
[root@db03 ~]# systemctl start mysqld
#查看进程启动失败,没有任何报错
#2.使用mysqld启动脚本启动
[root@db03 ~]# /etc/init.d/mysqld start
/etc/init.d/mysqld: line 244: my_print_defaults: command not found
/etc/init.d/mysqld: line 264: cd: /usr/local/mysql: No such file or directory
Starting MySQL ERROR! Couldn't find MySQL server (/usr/local/mysql/bin/mysqld_safe)
#原因:二进制的包是源码包已经生成编译安装完成的,在cmake阶段已经指定了所有的目录都是/usr/local/mysql,所以启动时所有程序都去找/usr/local/mysql目录,没有该目录,所以启动失败
#3.解决启动问题
1)方法一:做软连接
[root@db03 ~]# ln -s /service/mysql /usr/local/mysql
2)方法二:修改启动文件
[root@db03 ~]# vim /etc/init.d/mysqld
basedir=/service/mysql
datadir=/service/mysql/data
#4.再次测试启动
[root@db03 ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
#或者
[root@db03 ~]# systemctl start mysqld
12)设置环境变量
[root@db02 ~]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH
[root@db02 ~]# source /etc/profile
3.源码包安装
0)安装依赖
[root@db02 ~]# yum install -y ncurses-devel libaio-devel cmake glibc autoconf gcc-c++
1)上传包
[root@db02 ~]# rz mysql-5.6.42.tar.gz
2)解压
[root@db02 ~]# tar xf mysql-5.6.42.tar.gz
3)生成
#1.进入MySQL目录
[root@db02 ~]# cd mysql-5.6.42/
#2.创建安装目录
[root@db02 ~/mysql-5.6.42]# mkdir /service
#3.生成
[root@db02 mysql-5.6.42]#
#程序存放位置
cmake . -DCMAKE_INSTALL_PREFIX=/service/mysql-5.6.42 \
#数据存放位置
-DMYSQL_DATADIR=/service/mysql-5.6.42/data \
#socket文件存放位置
-DMYSQL_UNIX_ADDR=/service/mysql-5.6.42/data/mysql.sock \
#使用utf8字符集
-DDEFAULT_CHARSET=utf8 \
#校验规则
-DDEFAULT_COLLATION=utf8_general_ci \
#使用其他额外的字符集
-DWITH_EXTRA_CHARSETS=all \
#支持的存储引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
#禁用的存储引擎
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
#启用zlib库支持(zib、gzib相关)
-DWITH_ZLIB=bundled \
#启用SSL库支持(安全 套接层)
-DWITH_SSL=bundled \
#启用本地数据导入支持
-DENABLED_LOCAL_INFILE=1 \
#编译嵌入式服务器支持
-DWITH_EMBEDDED_SERVER=1 \
# mysql5.6支持了google的c++mock框架了,允许下载,否则会安装报错。
-DENABLE_DOWNLOADS=1 \
#禁用debug(默认为禁用)
-DWITH_DEBUG=0
cmake . -DCMAKE_INSTALL_PREFIX=/service/mysql-5.6.42 \
-DMYSQL_DATADIR=/service/mysql-5.6.42/data \
-DMYSQL_UNIX_ADDR=/service/mysql-5.6.42/data/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLE_DOWNLOADS=1 \
-DWITH_DEBUG=0
4)编译安装
[root@db02 ~/mysql-5.6.42]# make && make install
5)做软连接
[root@db02 ~]# ln -s /service/mysql-5.6.42 /service/mysql
7)创建用户
[root@db02 ~]# useradd mysql -s /sbin/nologin -M
8)拷贝启动文件和配置文件
[root@db02 ~]# cd /service/mysql/support-files/
[root@db02 /service/mysql/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite '/etc/my.cnf'? y
[root@db02 /service/mysql/support-files]# cp mysql.server /etc/init.d/mysqld
9)初始化
[root@db02 ~]# cd /service/mysql/scripts/
[root@db02 /service/mysql/scripts]# ./mysql_install_db --user=mysql --basedir=/service/mysql --datadir=/service/mysql/data
10)配置system管理启动MySQL
[root@db03 ~]# vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://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=/service/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
[root@db03 ~]# systemctl daemon-reload
11)设置环境变量
[root@db02 ~]# vim /etc/profile.d/mysql.sh
export PATH=/service/mysql/bin:$PATH
[root@db02 ~]# source /etc/profile
12)启动数据库
[root@db02 /service/mysql/scripts]# systemctl start mysqld
[root@db02 /service/mysql/scripts]# netstat -lntp