• 编译安装MySQL5.7.26


    编译安装MySQL5.7.26

    一、MySQL源码安装

    1.1.1 下载MySQL和Boost源码包

    1.官网下载:https://downloads.mysql.com/archives/community/

    2. 下载boost库(下载5.7版本,其它版本会报错)
    下载地址:https://www.boost.org/users/history/

    1.1.2 安装MySQL和Boost源码包

    1. YUM 下载依赖环境
    [root@blog /server/tools]# yum install gcc gcc-c++ ncurses ncurses-devel bison cmake make -y
    
    1. 解压Boost库
    [root@blog /server/tools]# mkdir /application/boost
    [root@blog /server/tools]# tar zxf boost_1_59_0.tar.gz 
    [root@blog /server/tools]# mv boost_1_59_0 /application/boost/
    [root@blog /server/tools]# ll /application/boost/
    total 4
    drwx------ 8 501 games 4096 Aug 12  2015 boost_1_59_0
    
    1. 创建MySQL管理用户
    [root@blog /server/tools]# useradd -M -s /sbin/nologin mysql
    [root@blog /server/tools]# id mysql
    uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)
    
    1. 创建数据存放目录
    [root@blog /server/tools]# mkdir /application/data/mysql -p
    [root@blog /server/tools]# chown -R mysql.mysql /application/data/
    [root@blog /server/tools]# ll -ld /application/data/
    drwxr-xr-x 3 mysql mysql 4096 May 25 11:55 /application/data/
    
    1. 解压安装mysql
    [root@blog /server/tools]# tar zxf mysql-boost-5.7.26.tar.gz 
    [root@blog /server/tools]# cd mysql-5.7.26/
    [root@blog /server/tools/mysql-5.7.26]# cmake . -DCMAKE_INSTALL_PREFIX=/application/mysql 
    -DMYSQL_DATADIR=/application/data/mysql 
    -DDOWNLOAD_BOOST=1 
    -DWITH_BOOST=/application/boost 
    -DSYSTEMD_PID_DIR=/application/data/mysql 
    -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 
    -DSYSCONFDIR=/etc 
    -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
    [root@blog /server/tools/mysql-5.7.26]# make && make install
    
    1. 创建配置文件my.cnf
    [root@blog /etc]# cd /etc/
    [root@blog /etc]# cp my.cnf my.cnf.default
    [root@blog /etc]# cat > /etc/my.cnf << EOF
    [client]
    port = 3306
    socket = /tmp/mysql.sock
    default-character-set = utf8mb4
    [mysqld]
    port = 3306
    socket = /tmp/mysql.sock
    basedir = /application/mysql
    datadir = /application/data/mysql
    pid-file = /application/data/mysql/mysql.pid
    user = mysql
    bind-address = 0.0.0.0
    server-id = 1
    init-connect = 'SET NAMES utf8mb4'
    character-set-server = utf8mb4
    #skip-name-resolve
    #skip-networking
    back_log = 300
    max_connections = 1000
    max_connect_errors = 6000
    open_files_limit = 65535
    table_open_cache = 128
    max_allowed_packet = 4M
    binlog_cache_size = 1M
    max_heap_table_size = 8M
    tmp_table_size = 16M
    read_buffer_size = 2M
    read_rnd_buffer_size = 8M
    sort_buffer_size = 8M
    join_buffer_size = 8M
    key_buffer_size = 4M
    thread_cache_size = 8
    query_cache_type = 1
    query_cache_size = 8M
    query_cache_limit = 2M
    ft_min_word_len = 4
    log_bin = mysql-bin
    binlog_format = mixed
    expire_logs_days = 30
    log_error = /application/data/mysql/mysql-error.log
    slow_query_log = 1
    long_query_time = 1
    slow_query_log_file = /application/data/mysql/mysql-slow.log
    performance_schema = 0
    explicit_defaults_for_timestamp
    #lower_case_table_names = 1
    skip-external-locking
    default_storage_engine = InnoDB
    #default-storage-engine = MyISAM
    innodb_file_per_table = 1
    innodb_open_files = 500
    innodb_buffer_pool_size = 64M
    innodb_write_io_threads = 4
    innodb_read_io_threads = 4
    innodb_thread_concurrency = 0
    innodb_purge_threads = 1
    innodb_flush_log_at_trx_commit = 2
    innodb_log_buffer_size = 2M
    innodb_log_file_size = 32M
    innodb_log_files_in_group = 3
    innodb_max_dirty_pages_pct = 90
    innodb_lock_wait_timeout = 120
    bulk_insert_buffer_size = 8M
    myisam_sort_buffer_size = 8M
    myisam_max_sort_file_size = 10G
    myisam_repair_threads = 1
    interactive_timeout = 28800
    wait_timeout = 28800
    [mysqldump]
    quick
    max_allowed_packet = 16M
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M
    EOF
    
    1. 初始化数据库
    [root@blog /etc]# /application/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/applicatio
    [root@blog /etc]# ll /application/data/mysql/
    total 110636
    -rw-r----- 1 mysql mysql       56 May 25 15:15 auto.cnf
    -rw-r----- 1 mysql mysql      419 May 25 15:15 ib_buffer_pool
    -rw-r----- 1 mysql mysql 12582912 May 25 15:15 ibdata1
    -rw-r----- 1 mysql mysql 33554432 May 25 15:15 ib_logfile0
    -rw-r----- 1 mysql mysql 33554432 May 25 15:15 ib_logfile1
    -rw-r----- 1 mysql mysql 33554432 May 25 15:15 ib_logfile2
    drwxr-x--- 2 mysql mysql     4096 May 25 15:15 mysql
    -rw-r----- 1 mysql mysql      177 May 25 15:15 mysql-bin.000001
    -rw-r----- 1 mysql mysql       19 May 25 15:15 mysql-bin.index
    -rw-r----- 1 mysql mysql      663 May 25 15:15 mysql-error.log
    -rw-r----- 1 mysql mysql      177 May 25 15:15 mysql-slow.log
    drwxr-x--- 2 mysql mysql     4096 May 25 15:15 performance_schema
    drwxr-x--- 2 mysql mysql    12288 May 25 15:15 sys
    
    1. 启动数据库
    [root@blog ~]# /application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    [root@blog ~]# ss -luntp | grep 3306
    tcp    LISTEN     0      128       *:3306                  *:*                   users:(("mysqld",pid=1109,fd=35))
    
    1. systemctl 管理MySQL
    [root@blog /usr/lib/systemd/system]# cp /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/mysqld.service
    [root@blog /usr/lib/systemd/system]# cat /usr/lib/systemd/system/mysqld.service
    [Unit]
    Description=MYSQL server 
    Documentation=https://dev.mysql.com/doc/refman/
    After=network.target 
    After=syslog.target 
    
    [Service]
    User=mysql
    Group=mysql
    EnvironmentFile=/etc/my.cnf
    ExecStart=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
    limitNOFILE=5000
    
    [Install]
    WantedBy=multi-user.target
    
    1. 设置环境变量
    [root@blog /usr/lib/systemd/system]# echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
    [root@blog /usr/lib/systemd/system]# tail -1 /etc/profile
    export PATH=/application/mysql/bin:$PATH
    [root@blog /usr/lib/systemd/system]# source /etc/profile
    [root@blog /usr/lib/systemd/system]# mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.26-log Source distribution
    
    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> 
    
    
    1. 设置数据库登录密码
    [root@blog ~]# mysqladmin -u root password
    New password: 
    Confirm new password: 
    Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
    #修改密码
    [root@blog ~]# mysqladmin -uroot -p旧密码 password 新密码
    
    1. 登录成功
    [root@blog ~]# mysql -u root -p
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 15
    Server version: 5.7.26-log Source distribution
    
    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.
    
    
  • 相关阅读:
    Codeforces Round #648 (Div. 2).D Solve The Maze
    Codeforces Round #648 (Div. 2).C Rotation Matching
    Codeforces Round #639 (Div. 2).C. Hilbert's Hotel
    C. Linova and Kingdom.Codeforces Round #635 (Div. 2)
    influxDB基本操作(详细)
    influxDB-介绍
    grafana的安装与启动
    104. HttpRequest对象详解
    103. 重定向详解
    102.限制请求的method装饰器:require_http_methods,require_GET,require_POST,require_safe
  • 原文地址:https://www.cnblogs.com/woaiyunwei/p/12957652.html
Copyright © 2020-2023  润新知