zoukankan      html  css  js  c++  java
  • CentOS 下 MySQL 5.7 编译安装

    MySQL5.7主要特性:

    1—更好的性能:对于多核CPU、固态硬盘、锁有着更好的优化,每秒100W QPS已不再是MySQL的追求,下个版本能否上200W QPS才是吾等用户更关心的

    2—更好的InnoDB存储引擎

    3—更为健壮的复制功能:复制带来了数据完全不丢失的方案,传统金融客户也可以选择使用MySQL数据库。此外,GTID在线平滑升级也变得可能

    4—更好的优化器:优化器代码重构的意义将在这个版本及以后的版本中带来巨大的改进,Oracle官方正在解决MySQL之前最大的难题

    5—原生JSON类型的支持

    6—更好的地理信息服务支持:InnoDB原生支持地理位置类型,支持GeoJSON,GeoHash特性

    7—新增sys库:以后这会是DBA访问最频繁的库

    安装依赖包

    yum -y install gcc gcc-c++ ncurses ncurses-devel cmake
    

    下载相应源码包

    cd /home/quant_group/mysql #cd /your/download/path
    wget http://downloads.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
    wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.11.tar.gz
    

    文件目录创建

    mkdir -p /home/quant_group/mysql/3306/data
    mkdir -p /home/quant_group/mysql/3306/tmp
    mkdir -p /home/quant_group/mysql/3306/log
    
    我们在这里是把mysql安装到/home目录下,没有安装到/下,防止系统出问题丢失数据
    

    添加mysql用户

    useradd -M -s /sbin/nologin mysql
    

    预编译

    tar xzf boost_1_59_0.tar.gz
    tar xzf mysql-5.7.11.tar.gz
    cd mysql-5.7.11
    cmake -DCMAKE_INSTALL_PREFIX=/home/quant_group/mysql/3306 
    -DMYSQL_DATADIR=/home/quant_group/mysql/3306/data 
    -DWITH_BOOST=/home/quant_group/mysql/boost_1_59_0 
    -DSYSCONFDIR=/home/quant_group/mysql 
    -DWITH_INNOBASE_STORAGE_ENGINE=1 
    -DWITH_PARTITION_STORAGE_ENGINE=1 
    -DWITH_FEDERATED_STORAGE_ENGINE=1 
    -DWITH_BLACKHOLE_STORAGE_ENGINE=1 
    -DWITH_MYISAM_STORAGE_ENGINE=1 
    -DENABLED_LOCAL_INFILE=1 
    -DENABLE_DTRACE=0 
    -DDEFAULT_CHARSET=utf8mb4 
    -DDEFAULT_COLLATION=utf8mb4_general_ci 
    -DWITH_EMBEDDED_SERVER=1
    

    编译安装

    make
    make install
    

    启动脚本,设置开机自启动

    /bin/cp /home/quant_group/mysql/3306/support-files/mysql.server /etc/init.d/mysqld
    chmod +x /etc/init.d/mysqld
    chkconfig --add mysqld
    chkconfig mysqld on
    

    /etc/my.cnf,仅供参考

    [mysqld]
    basedir = /home/quant_group/mysql/3306
    datadir = /home/quant_group/mysql/3306/data
    tmpdir = /home/quant_group/mysql/3306/tmp
    pid-file = /home/quant_group/mysql/3306/data/my.pid
    port = 3306
    
    default_storage_engine = InnoDB
    innodb_autoinc_lock_mode = 2
    
    explicit_defaults_for_timestamp = true
    character-set-client-handshake = FALSE
    character_set_server = utf8
    skip-name-resolve
    max_connect_errors = 1000000
    max_allowed_packet = 1G
    
    connect_timeout = 3600
    wait_timeout = 3600
    interactive_timeout = 3600
    innodb_lock_wait_timeout = 10
    slave-skip-errors  = 1032,1062
    log-error = /home/quant_group/mysql/3306/log/error.log
    
    slow_query_log = on
    slow_query_log_file = /home/quant_group/mysql/3306/log/slow-query-log.log
    long_query_time = 1
    log-queries-not-using-indexes
    log-slow-admin-statements
    log-slow-slave-statements
    
    server-id = 100
    log-bin = log-bin
    binlog-format = ROW
    

    初始化数据库

    chown -R mysql:mysql /home/quant_group/mysql/3306/
    cd /home/quant_group/mysql/3306/bin
    ./mysql_install_db --user=mysql --basedir=/home/quant_group/mysql/3306 --datadir=/home/quant_group/mysql/3306/data
    ###注:
    之前版本mysql_install_db是在mysql_basedir/script下,5.7放在了mysql_install_db/bin目录下,且已被废弃
    
    "--initialize"会生成一个随机密码(~/.mysql_secret),而"--initialize-insecure"不会生成密码
    
    --datadir目标目录下不能有数据文件
    

    启动 数据库

    service mysqld start
    # 启动不了可能是权限问题,把 mysql/3306下面都赋予mysql用户权限就好啦
    

    查看 密码

    view /root/.mysql_secret
    

    登录 数据库

    mysql -uroot -p'.U,tH2Cf3vRj' #这边密码要加引号,要么然的话存在转义问题
    如果提示 bash: mysql: command not found
    那么vim /root/.bash_profile  将mysql 的命令加进去
    比如:
        # .bash_profile
        # Get the aliases and functions
        if [ -f ~/.bashrc ]; then
            . ~/.bashrc
        fi
        # User specific environment and startup programs
        # PATH=$PATH:$HOME/bin  #修改前
        PATH=$PATH:$HOME/bin:/usr/local/mysql/bin #修改后
        export PATH
    然后 source /root/.bash_profile
    
    然后修改密码,比如修改root用户的新密码为123456
    SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
    

    如何删除数据库

    yum remove  mysql mysql-server mysql-libs mysql-server;
    
    find / -name mysql 将找到的相关东西delete掉;
    
    rpm -qa|grep mysql(查询出来的东东yum remove掉)
    

    创建用户

    The create user command:
    
        create user test identified by '123456';
        上面建立的用户可以在任何地方登陆。
    
        如果要限制在固定地址登陆,比如localhost 登陆:
        create user test@登录主机 identified by '123456';
    
    grant:
        grant all privileges on *.* to test@登录主机
        grant select,insert,update,delete on *.* to test@"%" Identified by "123456";
        格式:grant select on 数据库.* to 用户名@登录主机 identified by "密码"
    
    修改密码:
        grant all privileges on 数据库.* to test@登录主机 identified by '654321'; 
    flush:
        flush privileges; 
    查看用户信息:
        select host,user from mysql.user;
  • 相关阅读:
    BestCoder6 1002 Goffi and Squary Partition(hdu 4982) 解题报告
    codeforces 31C Schedule 解题报告
    codeforces 462C Appleman and Toastman 解题报告
    codeforces 460C. Present 解题报告
    BestCoder3 1002 BestCoder Sequence(hdu 4908) 解题报告
    BestCoder3 1001 Task schedule(hdu 4907) 解题报告
    poj 1195 Mobile phones 解题报告
    二维树状数组 探索进行中
    codeforces 460B Little Dima and Equation 解题报告
    通过Sql语句控制SQLite数据库增删改查
  • 原文地址:https://www.cnblogs.com/chunguang/p/5712086.html
Copyright © 2011-2022 走看看