在CentOS-6系统中二进制安装MySQL-5.6
安装并配置MySQL数据库
1、MySQL数据库的安装环境准备
a.内存配置最好2G以上
b.提前下载好要安装的MySQL相关软件包(https://downloads.mysql.com/archives/community/)
c.测试好系统可以连网,并配置好yum源
从2020.12.01 开始,CentOS官方及国内镜像网站都不再支持CenOS-6,所以最好是可以利用本地源,加上Vault源(CentOS会将不再支持的镜像全放到这个网站上)
d.配置CentOS-6的yum源
# 下载 CentOS-6.10-x86_64-bin-DVD1.iso 镜像,可以用来最小化装系统,还可以用来作为系统的本地源。挂载镜像到安装好的系统上。
[root@localhost ~]# mount /dev/cdrom /media/CentOS/
[root@localhost ~]# echo '/bin/mount /dev/cdrom /media/CentOS/' >> /etc/rc.local
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
# 只保留以下两个源,其它源都删除
[root@localhost ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 630 Dec 5 22:53 CentOS-Media.repo
-rw-r--r--. 1 root root 845 Dec 5 23:30 CentOS-Vault.repo
# 本地源配置文件,需要先把镜像挂载到指定目录
[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Media.repo
[c6-media]
name=CentOS-$releasever - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
# 公网源配置文件,只能配置vault.centos.org
[root@localhost ~]# cat /etc/yum.repos.d/CentOS-Vault.repo
[C6.9-base]
name=CentOS-6.9 - Base
baseurl=http://vault.centos.org/6.9/os/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
[C6.9-updates]
name=CentOS-6.9 - Updates
baseurl=http://vault.centos.org/6.9/updates/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
[C6.9-extras]
name=CentOS-6.9 - Extras
baseurl=http://vault.centos.org/6.9/extras/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
[C6.9-contrib]
name=CentOS-6.9 - Contrib
baseurl=http://vault.centos.org/6.9/contrib/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
[C6.9-centosplus]
name=CentOS-6.9 - CentOSPlus
baseurl=http://vault.centos.org/6.9/centosplus/$basearch/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=1
# 生成源文件
[root@localhost ~]# yum clean all & yum makecache
2、安装依赖包和环境
# 系统版本
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.10 (Final)
[root@localhost ~]# uname -r
2.6.32-754.el6.x86_64
[root@localhost ~]# uname -m
x86_64
# 安装依赖包
yum install ncurses-devel libaio-devel numactl -y
3、开始安装MySQL-5.6.49
# 下载 mysql-5.6.49-linux-glibc2.12-x86_64.tar.gz 二进制安装包,下载地址:
https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.49-linux-glibc2.12-x86_64.tar.gz
(1)建立MySQL用户账号
[root@localhost ~]# useradd -s /sbin/nologin -M mysql
[root@localhost ~]# id mysql
uid=500(mysql) gid=500(mysql) groups=500(mysql)
(2)获取MySQL软件包
第一步:上传软件
将下载好的 mysql-5.6.49-linux-glibc2.12-x86_64.tar.gz 上传到服务器上,放到目录 /server/tools 中。
第二步:解压配置mysql
tar xf mysql-5.6.49-linux-glibc2.12-x86_64.tar.gz
第三步:设置环境变量
[root@localhost ~]# echo 'export PATH="/application/mysql/bin:$PATH"' >>/etc/profile
mysql Ver 14.14 Distrib 5.6.49, for linux-glibc2.12 (x86_64) using EditLine wrapper
(3)创建MySQL数据库配置文件并对数据库目录授权
# 删除已有的 /etc/my.cnf
[root@localhost ~]# rm -f /etc/my.cnf
# 创建新的my.cnf
[root@localhost tools]# cat /etc/my.cnf
[mysql] # 设置mysql客户端默认字符集 [mysqld] #设置3306端口 # 设置mysql的安装目录 # 设置mysql数据库的数据的存放目录 # 允许最大连接数 # 服务端使用的字符集默认为8比特编码的latin1字符集 # 创建新表时将使用的默认存储引擎 |
# 对mysql数据目录授权
[root@localhost tools]# chown -R mysql.mysql /application/mysql
(4)初始化MySQL
[root@localhost mysql]# /application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data
4、配置并启动MySQL数据库
(1)设置MySQL脚本
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql]# chmod 700 /etc/init.d/mysqld
(2)启动MySQL数据库
[root@localhost mysql]# /etc/init.d/mysqld start 或 service mysqld start
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
(3)检查MySQL数据库是否启动
[root@localhost ~]# netstat -ntplu | grep mysql
tcp 0 0 :::3306 :::* LISTEN 2219/mysqld
(4)检查MySQL数据库启动结果日志
[root@localhost ~]# tail /application/mysql/data/localhost.localdomain.err
2020-12-06 05:30:16 2219 [Note] Server hostname (bind-address): '*'; port: 3306
2020-12-06 05:30:16 2219 [Note] IPv6 is available.
2020-12-06 05:30:16 2219 [Note] - '::' resolves to '::';
2020-12-06 05:30:16 2219 [Note] Server socket created on IP: '::'.
2020-12-06 05:30:16 2219 [Warning] 'user' entry 'root@localhost.localdomain' ignored in --skip-name-resolve mode.
2020-12-06 05:30:16 2219 [Warning] 'user' entry '@localhost.localdomain' ignored in --skip-name-resolve mode.
2020-12-06 05:30:16 2219 [Warning] 'proxies_priv' entry '@ root@localhost.localdomain' ignored in --skip-name-resolve mode.
2020-12-06 05:30:16 2219 [Note] Event Scheduler: Loaded 0 events
2020-12-06 05:30:16 2219 [Note] /application/mysql/bin/mysqld: ready for connections.
Version: '5.6.49' socket: '/tmp/mysql.sock' port: 3306 MySQL Community Server (GPL)
(5)设置MySQL开机自启动
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
5、登录MySQL测试
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.49 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, 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>