• linux下安装mysql5.7.11(二进制方式)


     版本:社区版 5.7.11


    我这里下载的是mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
    1.创建mysql用户和用户组
    #groupadd mysql
    #useradd -g mysql mysql
    #passwd mysql


    2.下载解压二进制文件,解压,进入解压出来的文件
    [root@host01 db]# tar -xvf mysql-5.7.11-linux-glibc2.5-x86_64.tar.gz
    [root@host01 db]# mv mysql-5.7.11-linux-glibc2.5-x86_64 mysqlmha
    [root@host01 mysqlmha]# ls -al
    total 60
    drwxr-xr-x  9 7161 wheel  4096 Feb  2 08:17 .
    drwxr-xr-x  4 root root   4096 Apr 11 13:16 ..
    drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 bin
    -rw-r--r--  1 7161 wheel 17987 Feb  2 07:31 COPYING
    drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 docs
    drwxr-xr-x  3 7161 wheel  4096 Feb  2 08:17 include
    drwxr-xr-x  5 7161 wheel  4096 Feb  2 08:17 lib
    drwxr-xr-x  4 7161 wheel  4096 Feb  2 08:17 man
    -rw-r--r--  1 7161 wheel  2478 Feb  2 07:31 README
    drwxr-xr-x 28 7161 wheel  4096 Feb  2 08:17 share
    drwxr-xr-x  2 7161 wheel  4096 Feb  2 08:17 support-files


    3.在mysqlmha下建立data和conf目录
    data目录存放数据文件,conf目录存放配置文件
    [mysql@host01 mysqlmha]$ cd /db/mysqlmha
    [mysql@host01 mysqlmha]$ mkdir data                        ##数据文件目录
    [mysql@host01 mysqlmha]$ mkdir conf                        ## 配置文件目录
    [mysql@host01 mysqlmha]$ mkdir redolog                    ##redo日志文件
    [mysql@host01 mysqlmha]$ mkdir ibdata                      ##ibdata文件
    [mysql@host01 mysqlmha]$ mkdir -p mysqllog/relaylog  ##主从环境relaylog
    [mysql@host01 mysqlmha]$ mkdir -p mysqllog/logfile    ##错误日志文件
    [mysql@host01 mysqlmha]$ mkdir -p mysqllog/binlog    ##binlog文件

    4.在conf目录下创建配置文件my.cnf,配置文件内容如下

    [mysqld]
    port=3306
    basedir=/db/mysqlmha
    datadir=/db/mysqlmha/data
    character-set-server=utf8
    max_connections = 1500
    show_compatibility_56=on


    [client]
    port = 3306
    socket=/db/mysqlmha/mysql.sock
    default-character-set = utf8

    [mysqldump]
    quick
    max_allowed_packet = 16M
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M

    5.更改文件夹mysqlmha的文件所属用户
    [root@host01 db]# chown -R mysql:mysql mysqlmha


    6.创建软连接
    [root@host01 db]# mkdir -p /usr/local/mysql/bin
    [root@host01 db]# ln -s /db/mysqlmha/bin/mysqld /usr/local/mysql/bin/mysqld


    7.初始化数据库

    root账户下
    root@host02 bin]# ./mysqld --initialize --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data --lc_messages_dir=/db/mysqlmha/share --lc_messages=en_US
    2016-12-09T20:36:23.865898Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2016-12-09T20:36:27.979029Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2016-12-09T20:36:28.110580Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2016-12-09T20:36:28.134481Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2906324e-be4f-11e6-bc0a-080027705c2d.
    2016-12-09T20:36:28.135350Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2016-12-09T20:36:28.136299Z 1 [Note] A temporary password is generated for root@localhost: kVQ2Nnsd:7oE
      我在另外一台机器执行如上命令的时候,系统没有任何的反应,后来发现之前安装过mariadb,etc目录下有my.cnf该文件,删除该文件再次执行即可。

    执行如上命令包如下错误,是因为没有安装libaio包的原因,执行yum install libaio* 安装即可.
    ./mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

     5.6版本采用mysql_install_db安装

    #./mysql_install_db --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data

    8.安装ssl_rsa
    [mysql@host01 bin]$ ./mysql_ssl_rsa_setup --user=mysql --basedir=/db/mysqlmha --datadir=/db/mysqlmha/data


    9.启动mysql(在mysql用户下执行)
    [mysql@host01 bin]$ ./mysqld_safe --defaults-file=/db/mysqlmha/conf/my.cnf --user=mysql


    启动报如下错误,是因为mysql-err.log文件不存,而mysql账号无法创建该文件(opt目录属主是root)
    2017-06-17T02:02:56.971570Z mysqld_safe error: log-error set to '/opt/mysql5718/mysqllog/logfile/mysql-err.log', however file don't exists. Create writable for user 'mysql'.

     手工创建该文件,并重新授权:
    [root@redis01 opt]# echo>/opt/mysql5718/mysqllog/logfile/mysql-err.log
    [root@redis01 opt]# chown -R mysql:mysql ./mysql5718

    11.登陆mysql并修改root密码
    [mysql@host01 bin]$ ./mysql -h localhost -u root  -p -S /db/mysqlmha/data/mysql.sock
    这里会提示输入密码,我们使用初始化临时提供的密码登陆,步骤7最后一句。
    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    这里必须要设置密码才能执行命令
    mysql> set password=password('mysql');
    Query OK, 0 rows affected, 1 warning (0.00 sec


    5.6版本的修改密码方法为:
    update mysql.user set password=PASSWORD('mysql') where user='root';
    flush privileges;


    12.创建登陆用户

    grant ALL on *.* to root@'192.168.56.%' identified by 'mysql' WITH GRANT OPTION;


    13.开机自启动
    把启动的语句添加到 /etc/rc.d/rc.local文件后面.
    赋予执行权限:
    [root@redis01 etc]# chmod +x /etc/rc.d/rc.local

    root@redis01 opt]# more /etc/rc.local
    #!/bin/bash
    # THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
    #
    # It is highly advisable to create own systemd services or udev rules
    # to run scripts during boot instead of using this file.
    #
    # In contrast to previous versions due to parallel execution during boot
    # this script will NOT be run after all other services.
    #
    # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
    # that this script will be executed during boot.


    touch /var/lock/subsys/local
    /opt/mysql5718/bin/mysqld_safe --defaults-file=/opt/mysql5718/conf/my.cnf --user=mysql



    后面附加上上线后配置文件的参数:
    [mysql@host02 conf]$ more my.cnf
    [mysqld]
    port=3306
    server-id=1
    datadir=/db/mysqlmha/data
    character-set-server=utf8
    max_connections = 1500
    skip-external-locking
    key_buffer_size=64M
    max_allowed_packet=32M
    myisam_sort_buffer_size=64M
    query_cache_size=32M
    read_buffer_size=2M
    sort_buffer_size=2M
    #table_cache=512
    #thread_cache=20
    #thread_concurrency=4
    interactive_timeout=86400
    wait_timeout=86400
    innodb_file_per_table=1
    #innodb_additional_mem_pool_size=16M
    innodb_buffer_pool_size=128M
    innodb_data_home_dir=/db/mysqlmha/ibdata
    innodb_data_file_path=ibdata1:100M;ibdata2:100M;ibdata3:100M;ibdata4:100M:autoextend
    ##这两个参数可以不用指定,要是指定的话,系统启动后会生成ibdata1,ibdata2..4,包括重新生成ibdata1,数据库刚安装的时候系统信息表全部是保留在ibdata1里的,这样的话,这些系统表就会提示不存在.
    innodb_flush_log_at_trx_commit=2
    innodb_lock_wait_timeout=50
    innodb_log_buffer_size=128M
    innodb_log_file_size=128M
    innodb_log_files_in_group=5
    innodb_log_group_home_dir=/db/mysqlmha/redolog
    innodb_thread_concurrency=8
    log_bin_trust_function_creators=1
    event_scheduler=1
    max_binlog_size=100M
    log-bin=/db/mysqlmha/mysqllog/binlog/binlog.bin
    slow_query_log=on
    slow_query_log_file=/db/mysqlmha/mysqllog/logfile/slow-query.log
    long_query_time=1 ##超过1秒就记录
    log-error=/db/mysqlmha/mysqllog/logfile/mysql-err.log
    binlog_format=row
    ##expire_logs_days=7
    binlog_cache_size=4MB
    skip-host-cache
    #skip-name-resolve
    #read-only
    skip-slave-start
    relay-log-index=/db/mysqlmha/mysqllog/relaylog/slave-relay-bin.index
    relay-log=/db/mysqlmha/mysqllog/relaylog/relaylog-binlog
    replicate-ignore-db=information_schema,performance_schema
    slave_net_timeout=60
    log_slave_updates=1
    ##lower_case_table_names=1
    language=/db/mysqlmha/share/english
    early-plugin-load=""
    explicit_defaults_for_timestamp=true
    gtid_mode=ON ##开启gtid
    enforce_gtid_consistency = ON

    transaction-isolation = READ-COMMITTED


    [client]
    port = 3306
    socket=/db/mysqlmha/mysql.sock
    default-character-set = utf8

    [mysqldump]
    quick
    max_allowed_packet = 32M
    [myisamchk]
    key_buffer_size = 8M
    sort_buffer_size = 8M
    read_buffer = 4M
    write_buffer = 4M

    -- The End --

  • 相关阅读:
    MySQL:如何查询出每个分组中的 top n 条记录?
    架构图解
    Jmeter(四十七)_性能测试统计超时率
    修改Docker容器启动配置参数
    Docker容器CPU、memory资源限制
    jmeter(四十六)参数化与断言实战
    jmeter(四十五)常用Beanshell脚本
    jmeter(四十四)常用性能指标分析
    linux性能监控常用命令
    jmap -heap 查看堆内存
  • 原文地址:https://www.cnblogs.com/hxlasky/p/12367585.html
Copyright © 2020-2023  润新知