IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]MySQL 5.7.16 centos下自动化安装

    mchdba发表于 2016-12-26 22:09:22
    love 0

     

    1,安装包下载地址

    官方下载地址:http://dev.mysql.com/downloads/mysql/,只保留最新的version,所以,需要的不一定有,我这里在百度云盘保留了下来,版本是5.7.16,可以随时去下载使用,分享地址:链接:http://pan.baidu.com/s/1jIhqSXw 密码:ifx5

     

    2,查看mysqld安装参数

    默认的官方文档安装是有初始化root密码的,而且那个密码很诡异,源码编译生成的还可以用,二进制或者rpm的不行,大家看如下官方的介绍:

    http://dev.mysql.com/doc/refman/5.7/en/binary-installation.html

    shell> groupadd mysql
    shell> useradd -r -g mysql -s /bin/false mysql
    shell> cd /usr/local
    shell> tar zxvf /path/to/mysql-VERSION-OS.tar.gz
    shell> ln -s full-path-to-mysql-VERSION-OS mysql
    shell> cd mysql
    shell> mkdir mysql-files
    shell> chmod 750 mysql-files
    shell> chown -R mysql .
    shell> chgrp -R mysql .
    shell> scripts/mysql_install_db --user=mysql# MySQL 5.7.0 to 5.7.4
    shell> bin/mysql_install_db --user=mysql    # MySQL 5.7.5
    shell> bin/mysqld --initialize --user=mysql # MySQL 5.7.6 and up
    shell> bin/mysql_ssl_rsa_setup              # MySQL 5.7.6 and up
    shell> chown -R root .
    shell> chown -R mysql data mysql-files
    shell> bin/mysqld_safe --user=mysql &
    # Next command is optional
    shell> cp support-files/mysql.server /etc/init.d/mysql.server

    Note

    This procedure assumes that you have root (administrator)access to your system. Alternatively, you can prefix each command using the sudo (Linux)or pfexec (OpenSolaris)command.

    Note

    Before MySQL 5.7.4, the procedure does not assign passwords toMySQL accounts. To do so, use the instructions in Section 2.10.4, “Securing the Initial MySQLAccounts”.

     

     

    但是这个初始化密码是可以去掉的,只是官方doc文档没有描述,大家可以通过mysqld --berbose –help来查找,如下所示:

    [root@02_sdw ~]# /usr/local/mysql/bin/mysqld --verbose --help |grep initialize

    mysqld: Can't change dir to '/usr/local/mysql/data/' (Errcode: 2 - No such file or directory)

                          GLOBAL.GTID_PURGED may be initialized wrongly in two

      --initialize        Create the default database and exit. Create a super user

      --initialize-insecure

    initialize                                                   FALSE

    initialize-insecure                                          FALSE

    [root@02_sdw ~]#

     

    原blog地址:http://blog.csdn.net/mchdba/article/details/53889781,作者mchdba,谢绝转载。

     

    3,自动化安装脚本

    编写自动化脚本auto_install_mysql5.7.end.sh来一键式安装,有个前提安装脚步、my.cnf和安装包mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz需要在同一个目录下,

    #!/bin/bash

    # install the basie lib

    useradd mysql

    yum install cmake -y

    yum install -y libtoolize

    yum install gcc gcc-c++ -y

    yum install -y ncurses-devel.x86_64

    yum install -y cmake.x86_64

    yum install -y libaio.x86_64

    yum install -y bison.x86_64

    yum install -y gcc-c++.x86_64

     

    # unzip

    #cp mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz /usr/local/

    tar -xvf mysql-5.7.16-linux-glibc2.5-x86_64.tar.gz -C /usr/local

    mv /usr/local/mysql-5.7.16-linux-glibc2.5-x86_64 /usr/local/mysql

    cp my.cnf /tmp/

    cp /tmp/my.cnf /usr/local/mysql/my.cnf

     

    # add mysql account,create the basic directory

    mkdir -p /data/mysql/data

    cd /data/mysql/data

    chown -R mysql:mysql /data

    chown -R mysql:mysql /usr/local/mysql

    mkdir -p /data/mysql/binlog/

    chown -R mysql:mysql /data/mysql/binlog/

     

    # init databases

    rm -rf /data/mysql/data/*

    cd /usr/local/mysql/

    time bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --initialize-insecure --user=mysql

     

    # set the auto start on linux server started

    cp support-files/mysql.server /etc/init.d/mysqld

    chmod 700 /etc/init.d/mysqld

    echo "export PATH=$PATH:/usr/local/mysql/bin">>/etc/profile

    #source /etc/profile

    chkconfig --add mysqld

     

    source /etc/profile

     

    # do a soft link to start mysql

    cd /usr/local/

    #ln -s mysql mysql

     

    # remove default my.cnf

    mv /etc/my.cnf /tmp/

     

    # start the mysql server

    service mysqld start

     

     

    4,执行脚本安装

    执行脚步bash -x auto_install_mysql5.7.end.sh安装完成,安装完成后,mysql登陆测试。

    [root@00_mdw soft]# mysql

    ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    [root@00_mdw soft]# ln -s /usr/local/mysql/mysql.sock /var/lib/mysql/mysql.sock

    [root@00_mdw soft]# mysql

    Welcome to the MySQL monitor.  Commands end with ; or \g.

    Your MySQL connection id is 2

    Server version: 5.7.16-log MySQL Community Server (GPL)

     

    Copyright (c) 2000, 2012, 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>

     

     

    参考文档地址:

    https://docs.google.com/document/pub?id=1qgOspAux65N0HnOzEWPs7IpccU1i3bHg1EYedyCxmVQ

     



沪ICP备19023445号-2号
友情链接