CentOS7环境下免编译二进制包安装MySQL5.6教程
cd /usr/local.src/ 进入默认下载目录
wget https://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.38.tar.gz
tar zxvf mysql-5.6.38.tar.gz 解压
mv mysql-5.6.38-linux-glibc2.12-x86_64 /usr/local/mysql 移动目录位置并重命名
cd /usr/local/mysql/
groupadd mysql 创建mysql组
useradd -g mysql -s /sbin/nologin -M mysql 创建mysql用户,禁止登陆且不创建家目录
mkdir -p /data/mysql 创建datadir,数据库文件会放在这里
chown -R mysql.mysql /data/mysql 更改权限
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
有可能报错说缺少perl-Module-Install包
使用yum install -y perl-Module-Install安装
echo $?检查有没有错误(一般看到两个OK就是成功没问题了)
cp support-files/my-default.cnf /etc/my.cnf 复制配置文件
vim /etc/my.cnf 配置文件修改如下
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin = qiulinux
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql
datadir = /data/mysql
port = 3306
server_id = 128
socket = /tmp/mysql.sock
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
join_buffer_size = 128M
sort_buffer_size = 2M
read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
basedir是MySQL包所在路径
datadir是定义的存放数据的地方
port是定义MySQL服务监听的端口,默认3306
server_id是定义该MySQL服务的ID号,主要用在做主从配置上
socket是定义MySQL服务监听的套接字地址
剩下几个buffer是关于内存的配置参数,默认即可
cp support-files/mysql.server /etc/init.d/mysqld 复制启动脚本文件
chmod 755 /etc/init.d/mysqld 更改权限
vim /etc/init.d/mysqld 启动脚本文件修改如下
basedir=/usr/local/mysql
datadir=/data/mysql
设置开机启动并启动MySQL
chkconfig --add mysqld 把mysqld服务加入系统服务列表
chkconfig mysqld on 使其开机启动
service mysqld start 启动服务
ps aux | grep mysqld 结果应该大于2行
netstat -lnp |grep 3306 查看是否监听3306端口