一.环境声明
[mysql-Server]
-
主机名
= host-1
-
系统
= centos-7.3
-
地址
=
1.1.1.1
-
软件
= mysql-5.6.39
3306
使用二进制包部署会下载比较大,大约500M左右,而源码包就几十M。但使用二进制包不用编译,部署较快,相比于yum可以自定义目录,方便维护。
二.程序部署
1.安装依赖
yum -y install autoconf libaio bison ncurses-devel
2.创建用户
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
3.清理centos7 默认自带数据库
yum -y remove mariadb mariadb-server
4.下载MySQL
wget https://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
5.安装
tar -xf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
mkdir /var/log/mysql
mkdir /usr/local/mysql/data
mysql即使root启动还是mysql用户运行的,所以要给权限
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/log/mysql
6.修改配置,具体再根据性能和需求修改
vim /etc/my.cnf
[mysql]
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock
[mysqld]
skip-name-resolve
port =
3306
socket=/usr/local/mysql/mysql.sock
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
max_connection=200
character-set-server=utf8
default-storage-engine=INNODB
lower_case_table_name=1
max_allowed_packet=16M
log-error=/var/log/mysql/mysql.log
pid-file=/var/log/mysql/mysql.pid
bind-address =
0.0.0.0
7.启动服务
cd /usr/local/mysql
进行初始化操作
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/
让mysql可以读
chown mysql:mysql /etc/my.cnf
8.加入systemctl
vim /usr/lib/systemd/system/mysql.service
[Unit]
Description=mysql
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecReload=/usr/local/mysql/support-files/mysql.server restart
ExecStop=/usr/local/mysql/support-files/mysql.server stop
PrivateTmp=true
[Install]
WantedBy=multi-user.target
9.设置环境变量
echo 'PATH=$PATH':/usr/local/mysql/bin >> /etc/profile
source /etc/profile
10.启动并加入自启动
systemctl start mysql
systemctl enable mysql