1. 程式人生 > 實用技巧 >MySQL5.7.30二進位制部署

MySQL5.7.30二進位制部署

官網下載二進位制包

  • wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz

解壓

  • tar -zxf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
    cd /usr/local && mv mysql-5.7.30-linux-glibc2.12-x86_64/ mysql 
    cd mysql && mkdir data

配置環境變數

  • echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile
    source /etc/profile

建立MySQL使用者並初始化

  • useradd -s /sbin/nologin mysql -M
    yum -y install libaio*
    mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
     注:--initialize引數是開啟臨時密碼、安全策略(密碼過期時間)      

修改配置檔案

  • cp /etc/my.cnf /tmp
    
    vim /etc/my.cnf
    [mysqld]
    user=mysql
    bind-address=0.0.0.0
    basedir=/usr/local/mysql
    datadir=/usr/local/mysql/data
    socket=/tmp/mysql.sock
    server_id=1
    [mysql]
    socket=/tmp/mysql.sock
    

      

新增system管理啟動

  • vim  /usr/lib/systemd/system/mysqld.service
    [Unit] Description=MySQL Server Documentation=man:mysqld(8) Documentation=http://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

啟動Mysql服務

  • systemctl daemon-reload
    systemctl start mysqld
    netstat -lntp | grep 3306