mysql的安装

作者: OrangeLoveMilan | 来源:发表于2017-12-23 17:54 被阅读27次

    1、环境

    IP 192.168.109.111
    mysql 5.7

    2、mysql安装

    2.1 查看是否存在mysql组合用户,若无则创建

    cat /etc/group | grep mysql
    cat /etc/passwd | grep mysql
    groupadd mysql
    useradd -r -g mysql mysql
    

    2.2 准备工作

    (1)传mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz 到/usr/local

    (2)这里mysql数据目录暂定为/data/mysql/ 日志目录为/data/mysql/log
    mkdir -p /data/mysql3306
    chown -R mysql:mysql /data/mysql3306

    2.3 开始安装

    cd /usr/local/
    tar -xf mysql-5.7.14-linux-glibc2.5-x86_64.tar.gz
    mv mysql-5.7.14-linux-glibc2.5-x86_64 mysql3306
    chown -R mysql:mysql mysql3306/
    cd mysql3306/
    bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql3306/ --datadir=/data/mysql3306/
    cp -a ./support-files/my-default.cnf /etc/my3306.cnf
    cp -a ./support-files/mysql.server /etc/init.d/mysqld3306
    

    2.4 修改/etc/my3306.cnf配置文件,启动mysql

    my.cnf配置如下

    cat >/etc/my3306.cnf<<EOF
    [client]
    port = 3306
    socket = /tmp/mysql.sock
    
    [mysqld]
    basedir = /usr/local/mysql
    port = 3306
    socket = /tmp/mysql.sock
    datadir = /data/mysql/
    pid-file = /data/mysql/mysql.pid
    log-error = /data/mysql/log/mysql.err
    
    server-id = 1
    #auto_increment_offset = 1
    #auto_increment_increment = 2                                            #奇数ID
    
    log-bin = mysql-bin                                                     #打开二进制功能,MASTER主服务器必须打开此项
    binlog-format=mixed
    #log-slave-updates=true
    gtid-mode=on
    enforce-gtid-consistency=true
    master-info-repository=TABLE
    #relay-log-info-repository=TABLE
    #sync-master-info=1
    slave-parallel-workers=0
    #sync_binlog=0
    binlog-checksum=CRC32
    master-verify-checksum=1
    slave-sql-verify-checksum=1
    binlog-rows-query-log_events=1
    expire_logs_days=7
    max_binlog_size=1024M                                                   #binlog单文件最大值
    
    #replicate-ignore-db = mysql                                             #忽略不同步主从的数据库
    #replicate-ignore-db = information_schema
    #replicate-ignore-db = performance_schema
    #replicate-ignore-db = test
    #replicate-ignore-db = zabbix
    
    max_connections = 3000
    max_connect_errors = 30
    
    #skip-character-set-client-handshake                                     #忽略应用程序想要设置的其他字符集
    #init-connect='SET NAMES utf8'                                           #连接时执行的SQL
    character-set-server=utf8                                               #服务端默认字符集
    wait_timeout=1800                                                       #请求的最大连接时间
    interactive_timeout=1800                                                #和上一参数同时修改才会生效
    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES                     #sql模式
    max_allowed_packet = 10M
    bulk_insert_buffer_size = 8M
    query_cache_type = 1
    query_cache_size = 128M
    query_cache_limit = 4M
    key_buffer_size = 256M
    read_buffer_size = 16K
    
    skip-name-resolve
    slow_query_log=1
    long_query_time = 6
    slow_query_log_file=slow-query.log
    innodb_flush_log_at_trx_commit = 2
    innodb_log_buffer_size = 16M
    
    [mysql]
    no-auto-rehash
    
    [myisamchk]
    key_buffer_size = 20M
    sort_buffer_size = 20M
    read_buffer = 2M
    write_buffer = 2M
    
    [mysqlhotcopy]
    interactive-timeout
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysqld_safe]
    EOF
    

    启动mysql
    在 /etc/init.d/mysqld3306的46,47行添加

    basedir=/usr/local/mysql3306
    datadir=/data/mysql3306
    

    重启mysql
    service mysqld3306 start

    5 修改mysql密码

    cat /root/.mysql_secret
    记录了mysql的初始密码
    cd /usr/local/mysql/bin

    ./mysql -uroot -p
    输入密码 进入mysql数据库

    SET PASSWORD = PASSWORD('123456');
    grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
    flush privileges;
    

    6添加环境变量

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

    相关文章

      网友评论

        本文标题:mysql的安装

        本文链接:https://www.haomeiwen.com/subject/odpqgxtx.html