centos7部署二进制mysql-5.6

2021-06-08 18:15:35 浏览数 (1)

一.环境声明

  1. [mysql-Server]
  2. 主机名 = host-1
  3. 系统 = centos-7.3
  4. 地址 = 1.1.1.1
  5. 软件 = 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

  1. [mysql]
  2. default-character-set=utf8
  3. socket=/usr/local/mysql/mysql.sock
  4. [mysqld]
  5. skip-name-resolve
  6. port = 3306
  7. socket=/usr/local/mysql/mysql.sock
  8. basedir=/usr/local/mysql
  9. datadir=/usr/local/mysql/data
  10. max_connection=200
  11. character-set-server=utf8
  12. default-storage-engine=INNODB
  13. lower_case_table_name=1
  14. max_allowed_packet=16M
  15. log-error=/var/log/mysql/mysql.log
  16. pid-file=/var/log/mysql/mysql.pid
  17. 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

  1. [Unit]
  2. Description=mysql
  3. After=network.target remote-fs.target nss-lookup.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/usr/local/mysql/support-files/mysql.server start
  7. ExecReload=/usr/local/mysql/support-files/mysql.server restart
  8. ExecStop=/usr/local/mysql/support-files/mysql.server stop
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

9.设置环境变量 echo 'PATH=$PATH':/usr/local/mysql/bin >> /etc/profile source /etc/profile

10.启动并加入自启动 systemctl start mysql systemctl enable mysql

0 人点赞