zoukankan      html  css  js  c++  java
  • MySQL 二进制安装

    下载 Mysql 二进制包

    [root@web01 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
    

    安装依赖

    [root@m01 ~]# yum install -y ncurses-devel libaio-devel gcc gcc-c++ glibc cmake autoconf openssl openssl-devel
    

    解压包

    [root@m01 ~]# tar xf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
    

    移动目录

    [root@m01 ~]# mv mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/
    

    做软连接

    [root@m01 ~]# ln -s /usr/local/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql
    

    创建 mysql 用户

    [root@m01 ~]# useradd mysql -r -s /sbin/nologin -M
    

    拷贝配置文件和启动脚本

    [root@m01 support-files]# cp my-default.cnf /etc/my.cnf
    cp: overwrite ‘/etc/my.cnf’? y
    
    [root@m01 support-files]# cp mysql.server /etc/init.d/mysqld
    

    初始化数据库

    [root@m01 ~]# cd /usr/local/mysql/scripts/
    [root@m01 scripts]# ./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
    
    --user:	指定用户
    --basedir: 指定安装目录
    --datadir: 指定数据目录
    
    # 初始化成功的标志是两个ok
    

    启动数据库

    [root@m01 scripts]# /etc/init.d/mysqld start
    

    配置环境变量

    [root@m01 scripts]# vim /etc/profile.d/mysql.sh
    export PATH=/usr/local/mysql/bin:$PATH
    
    [root@m01 scripts]# source /etc/profile
    

    配置system管理mysql

    [root@m01 scripts]# vim /usr/lib/systemd/system/mysqld.service
    [Unit]
    Description=MySQL Server
    Documentation=man:mysqld(8)
    Documentation=https://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
    
    [root@m01 scripts]# systemctl daemon-reload
    [root@m01 scripts]# systemctl start mysqld
    

    确认启动

    [root@m01 scripts]# ps -ef | grep mysql
    mysql     12886      1  2 03:10 ?        00:00:00 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    root      12921  10636  0 03:11 pts/1    00:00:00 grep --color=auto mysql
    [root@m01 scripts]# netstat -lntp
    Active Internet connections (only servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
    tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      12027/redis-server  
    tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      6180/rpcbind        
    tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      7113/sshd           
    tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      7198/master         
    tcp6       0      0 :::3306                 :::*                    LISTEN      12886/mysqld        
    tcp6       0      0 :::111                  :::*                    LISTEN      6180/rpcbind        
    tcp6       0      0 :::22                   :::*                    LISTEN      7113/sshd           
    tcp6       0      0 ::1:25                  :::*                    LISTEN      7198/master         
    [root@m01 scripts]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 1
    Server version: 5.6.46 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2019, 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>
    

    不安装在 /usr/local 目录下会遇到的问题

    [root@m01 scripts]# /etc/init.d/mysqld start
    
    # 启动失败,因为mysql文件中很多都是 /usr/local/mysql,我们需要替换,但只需要替换两个文件中的内容即可
    [root@m01 mysql]# sed -i 's#/usr/local/mysql#/service/mysql#g' /etc/init.d/mysqld /service/mysql/bin/mysqld_safe 
     
    # 修改配置文件
    [root@m01 mysql]# vim /etc/my.cnf
    basedir = /service/mysql
    datadir = /service/mysql/data
    
    # 再次启动
    [root@m01 mysql]# /etc/init.d/mysqld start
    Starting MySQL.Logging to '/service/mysql/data/db03.err'.
     SUCCESS! 
    
  • 相关阅读:
    devise 异步发邮件
    ubuntutweak for lucid
    960gs blueprint
    Amoeba for mysql 0.31发布(读写分离、负载均衡、Failover、数据切分)
    Google App Servlet容器转型 – 从Tomcat到Jetty
    DBeaver
    用simple from暂不用formtastic
    [SQL Server]ORDER BY的问题
    PHP pathinfo() 函数
    php中使用head进行二进制流输出,让用户下载PDF等附件的方法
  • 原文地址:https://www.cnblogs.com/zzzwqh/p/13271989.html
Copyright © 2011-2022 走看看