zoukankan      html  css  js  c++  java
  • Linux安装mysql

    1 安装前的准备:

           mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

    2 安装并解压

          在Hadoop001上安装Mysql数据库,这里数据库的版本是mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz,将mysql安装包上传到服         务器,或者从官网上下载mysql安装包.

         解压mysql安装包:tar xzvf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz

         解压完毕之后,将解压后的目录移动到/usr/local目录下(固定目录)

        (或者直接解压到/usr/local:tar -vxf mysql-5.6.23-linux-glibc2.5-x86_64.tar.gz -C /usr/local)

        并改名为mysql:   mv mysql-5.6.23-linux-glibc2.5-x86_64 /usr/local/mysql

    3 改变mysql的用户组

        将mysql添加到mysqladmin的dba用户组里

        执行: groupadd -g 101 dba

                    useradd -u 514 -g dba -G root -d /usr/local/mysql mysqladmin

       查看用户是否已添加:id mysqladmin

       执行:passwd mysqladmin

       更改mysqladmin 用户的密码

       执行:cp /etc/skel/.* /usr/local/mysql

       将环境变量配置文件拷贝到mysqladmin用户的home目录下

       创建mysql的配置文件

             执行: cd /etc/

                         vim my.cnf

             进入到my.cnf文件之后,讲里面的全部内容删除,之后将以下的配置拷贝到my.cnf中:  

    [client]
    port            = 3306
    socket          = /usr/local/mysql/data/mysql.sock
    [mysqld]
    port            = 3306
    socket          = /usr/local/mysql/data/mysql.sock
    
    skip-external-locking
    key_buffer_size = 256M
    sort_buffer_size = 2M
    read_buffer_size = 2M
    read_rnd_buffer_size = 4M
    query_cache_size= 32M
    max_allowed_packet = 16M
    myisam_sort_buffer_size=128M
    tmp_table_size=32M
    table_open_cache = 512
    thread_cache_size = 8
    wait_timeout = 86400
    interactive_timeout = 86400
    max_connections = 600
    thread_concurrency = 32
    default-storage-engine = INNODB
    transaction-isolation = READ-COMMITTED
    server-id  = 1
    basedir     = /usr/local/mysql
    datadir     = /usr/local/mysql/data
    pid-file     = /usr/local/mysql/data/hostname.pid
    log-warnings
    sysdate-is-now
    binlog_format = MIXED
    log_bin_trust_function_creators=1
    log-error  = /usr/local/mysql/data/hostname.err
    log-bin=/usr/local/mysql/arch/mysql-bin
    innodb_data_home_dir = /usr/local/mysql/data/
    innodb_data_file_path = ibdata1:500M:autoextend
    innodb_log_group_home_dir = /usr/local/mysql/arch
    innodb_log_files_in_group = 2
    innodb_log_file_size = 200M
    innodb_buffer_pool_size = 1024M
    innodb_additional_mem_pool_size = 50M
    innodb_log_buffer_size = 16M
    innodb_lock_wait_timeout = 100
    innodb_flush_log_at_trx_commit = 1
    innodb_locks_unsafe_for_binlog=1
    performance_schema
    innodb_read_io_threads=4
    innodb-write-io-threads=4
    innodb-io-capacity=200
    innodb_purge_threads=1
    innodb_use_native_aio=on
    innodb_file_per_table = 1
    lower_case_table_names=1
    
    [mysqldump]
    quick
    max_allowed_packet = 16M
    
    [mysql]
    no-auto-rehash
    
    [mysqlhotcopy]
    interactive-timeout
    
    [myisamchk]
    key_buffer_size = 256M
    sort_buffer_size = 256M
    read_buffer = 2M
    write_buffer = 2M

     

    4 修改my.cnf文件的属性和权限

        执行:chown  mysqladmin:dba /etc/my.cnf

                   chmod  640 /etc/my.cnf  

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

                   chmod -R 755 /usr/local/mysql

                   su - mysqladmin

                        执行完之后,看一下当前的路径

                        执行:pwd

                               看一下是否在/usr/local/mysql路径下

                        执行:mkdir arch backup

                         执行初始化脚本:

                          /usr/local/mysql/scripts/mysql_install_db   --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysqladmin        

                         打印的日志没有报错,说明运行ok。

    5 配置mysql服务和自启动

                                 执行:su root

                                           cd /usr/local/mysql

                                           cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysql

                                           chmod +x /etc/rc.d/init.d/mysql

                                           chkconfig --del mysql

                                           chkconfig --add mysql

                                           chkconfig --level 345 mysql on

            打开/etc/rc.local文件

            执行:vim /etc/rc.local

            将里面的内容都删掉,拷贝以下内容:

    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.
    touch /var/lock/subsys/local
    su - mysqladmin -c "/etc/init.d/mysql start --federated"
    "/etc/rc.local" 9L, 278C written

    启动mysql并监听进程

           执行:su - mysqladmin

                      mysqld_safe &

           执行完之后回车

           执行:ps -ef|grep mysqld

           查看mysql的进程是否运行

           执行:service mysql status

           出现上图代表启动ok

    7 修改mysql的密码

           执行:mysql

           进入到mysql的控制台

           执行:use mysql

                      update user set password=password('root') where user='root';

           这里将mysql的账号密码都设置为root

                  执行:select host,user,password from user;

           将空字段删掉;

                  执行:delete from user where user='';

           重新查询一遍:select host,user,password from user;

                空字段删掉ok

           执行:flush privileges;

           退出mysql控制台;

    8 更改.bash_profile文件

             进入到mysql目录中,执行vim ./.bash_profile

             把里面的内容清空,并粘贴以下

    # .bash_profile
    # Get the aliases and functions
    if [ -f ~/.bashrc ]; then
    
            . ~/.bashrc
    
    fi
    
    # User specific environment and startup programs
    
    MYSQL_BASE=/usr/local/mysql
    
    export MYSQL_BASE
    
    PATH=${MYSQL_BASE}/bin:$PATH
    
    export PATH
    unset USERNAME
    
    #stty erase ^H
    
    set umask to 022
    
    umask 022
    
    PS1=`uname -n`":"'$USER'":"'$PWD'":>"; export PS1

        保存退出

     

    9 开启外部访问权限

           登录到mysql中:mysql -uroot -proot

                            执行:use mysql ;

                                       grant  all on *.* to 'root'@'%'  identified by 'root' ;

                                        flush privileges;

  • 相关阅读:
    【NOIP2013提高组T3】货车运输-最大生成树+倍增LCA
    【POJ1986】Distance Queries-LCA算法
    【POJ1986】Distance Queries-LCA算法
    【HDU2874】Connections between cities-LCA算法
    【HDU2874】Connections between cities-LCA算法
    【HDU2586】How far away?-LCA算法模板题
    js ajax调用请求
    js ajax调用请求
    ThinkPHP 3.1.2 视图 2
    ThinkPHP 3.1.2 视图 2
  • 原文地址:https://www.cnblogs.com/t0404/p/10290928.html
Copyright © 2011-2022 走看看