zoukankan      html  css  js  c++  java
  • CentOS6.6安装mysql-5.7.25二进制安装包简易教程

    #####1,安装前首先确认系统版本

    [root@bogon:~]# cat /etc/redhat-release
    CentOS release 6.6 (Final)
    [root@bogon:~]# uname -r
    2.6.32-504.el6.x86_64
    [root@bogon:~]# uname -m
    x86_64
    
    2,排除系统中存在的mysql和mariadb
    [root@bogon:~]# rpm -qa|egrep "mysql|mariadb"
    mysql-libs-5.1.73-3.el6_5.x86_64
    [root@bogon:~]# rpm -e --nodeps mysql-libs-5.1.73-3.el6_5.x86_64
    #包括/var/lib/mysql下的文件也需要清空(可以通过find / -name "mysql"来查找)
    
    3,从官网下载二进制安装包,创建存放软件包的文件,并通过rsync把软件从本地上传到服务器指定位置,并用md5校验文件的准确性
    [root@bogon:/home/hejian/tools]# rsync -avzP -e "ssh -p 22" hejian@192.168.0.103:/Users/hejian/Desktop/mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz .
    [root@bogon:/home/hejian/tools]# md5sum mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
    d241f5dd6527cf1f9ff39449538c1eb1  mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz
    
    4,把mysl解压到指定文件夹,并创建软链接
    [root@bogon:/home/hejian/tools]# mkdir -p /application
    [root@bogon:/home/hejian/tools]# tar -xf mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz -C /application/
    
    
    5,创建mysql用户,并给mysql文件夹授权
    [root@bogon:/application]# useradd -s /sbin/nologin -M mysql
    [root@bogon:/application]# chown -R mysql.mysql /application/mysql
    
    6,创建my-default.cnf配置文件,并拷贝到/etc下

    从5.7.18版本开始,已经不提供my-default.cnf文件

    [client]
    port = 3306
    socket = /tmp/mysql.sock
    
    [mysqld]
    
    #设置3306端口
    port = 3306
    
    #设置socke文件所在目录
    socket=/tmp/mysql.sock
    
    # 设置mysql的安装目录
    basedir=/application/mysql
    
    # 设置mysql数据库的数据的存放目录
    datadir=/application/mysql/data
    
    # 允许最大连接数
    max_connections=200
    
    #SQL数据包发送的大小
    max_allowed_packet = 128M
    
    # 服务端使用的字符集默认为latin1字符集
    character-set-server=utf8
    
    # 创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB
    
    [mysqld_safe]
    #数据库错误日志文件
    log_error =/application/mysql/data/error.log
    
    [root@bogon:/application/mysql/support-files]# cp my-default.cnf /etc/my.cnf
    
    7,对mysql进行初始化,会5.7以后用--initialize来初始化,并最后生成一个随机密码
    [root@bogon:/application/mysql]# ./bin/mysqld --initialize --basedir=/application/mysql/ --datadir=/application/mysql/data/ --user=mysql
    2019-04-11T11:51:03.883359Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2019-04-11T11:51:04.624279Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2019-04-11T11:51:04.714769Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2019-04-11T11:51:04.792980Z 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: 1602c2e3-5c50-11e9-98d6-000c2933615e.
    2019-04-11T11:51:04.794419Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2019-04-11T11:51:04.798256Z 1 [Note] A temporary password is generated for root@localhost: &jKQaE6rE77b
    
    8,设置加密连接
    [root@bogon:/application/mysql]# /application/mysql/bin//mysql_ssl_rsa_setup
    Generating a 2048 bit RSA private key
    ..+++
    ..............+++
    writing new private key to 'ca-key.pem'
    -----
    Generating a 2048 bit RSA private key
    ........................................+++
    .......................+++
    writing new private key to 'server-key.pem'
    -----
    Generating a 2048 bit RSA private key
    ..............................+++
    ..............................................................................................................+++
    writing new private key to 'client-key.pem'
    -----
    
    9,配置系统的方式启动MySQL,并设置开机自启动
    [root@bogon:/application/mysql]# cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
    
    

    由于mysql默认的安装路径是/usr/local/mysql,需要对mysqld脚本下的文件做个替换

    [root@bogon:/application/mysql]# sed -i 's#/usr/local#/application#g' /etc/init.d/mysqld
    

    然后启动mysql,并设置开机自启动

    [root@bogon:/application]# /etc/init.d/mysqld start
    [root@bogon:/application]# netstat -tunlp|grep mysqld
    tcp        0      0 :::3306                     :::*                        LISTEN      25092/mysqld
    
    [root@bogon:/application]# chkconfig mysqld on
    [root@bogon:/application]# chkconfig --list|grep mysqld
    mysqld         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
    
    10,配置环境变量
    vim /etc/profile
    PATH="/application/mysql/bin:$PATH"
    source /etc/profile
    
    11,然后输入第7步生成的随机密码,就可以正常登录了
    [root@bogon:/application]#  mysql -hlocalhost -uroot -p
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 6
    Server version: 5.7.25
    
    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>
    

    登录进去初次必须修改密码

    mysql> show databases;
    ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
    mysql> set password=password("123456");
    mysql> flush privileges;
    

    mysql成功安装完毕!

  • 相关阅读:
    《JAVA设计模式》之模板模式(Template)
    《JAVA设计模式》之策略模式(Strategy)
    《JAVA设计模式》之享元模式(Flyweight)
    《JAVA设计模式》之桥接模式(Bridge)
    《JAVA设计模式》之组合模式(Composite)
    《JAVA设计模式》之外观模式(Facade)
    《JAVA设计模式》之代理模式(Proxy)
    《JAVA设计模式》之装饰模式(Decorator)
    《JAVA设计模式》之适配器模式(Adapter)
    《JAVA设计模式》之原型模式(Prototype)
  • 原文地址:https://www.cnblogs.com/hejian2836/p/10692363.html
Copyright © 2011-2022 走看看