• MySql离线安装(OS7系统)


    服务器环境:

    centos7 x64

    需要安装mysql5.7+

    一、卸载CentOS7系统自带mariadb

    复制代码
    # 查看系统自带的Mariadb
    [root@CDH-141 ~]# rpm -qa|grep mariadb
    mariadb-libs-5.5.44-2.el7.centos.x86_64
    # 卸载系统自带的Mariadb
    [root@CDH-141 ~]# rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64
    # 删除etc目录下的my.cnf
    [root@CDH-141 ~]# rm /etc/my.cnf
    复制代码

    二、检查mysql是否存在

    # 检查mysql是否存在
    [root@CDH-141 ~]# rpm -qa | grep mysql
    [root@CDH-141 ~]# 

    三、查看用户和组是否存在

    1)检查mysql组合用户是否存在

    # 检查mysql组和用户是否存在,如无则创建
    [root@CDH-141 ~]# cat /etc/group | grep mysql
    [root@CDH-141 ~]# cat /etc/passwd | grep mysql 

    2)若不存在,则创建mysql组和用户

    复制代码
    # 创建mysql用户组
    [root@CDH-141 ~]# groupadd mysql
    # 创建一个用户名为mysql的用户,并加入mysql用户组
    [root@CDH-141 ~]# useradd -g mysql mysql
    # 制定password 为mysql
    [root@CDH-141 ~]# passwd mysql
    Changing password for user mysql.
    New password:
    BAD PASSWORD: The password is a palindrome
    Retype new password:
    passwd: all authentication tokens updated successfully.

    四、下载mysql离线安装包tar文件

    官网下载地址:https://dev.mysql.com/downloads/mysql/5.7.html#downloads

    版本选择,可以选择一下两种方式:

    1)使用Red Hat Enterprise Linux
    Select Version:5.7.25
    Select Operating System:Red Hat Enterprise Linux / Oracle Linux
    Select OS Version:Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit)
    列表中下载:
    Compressed TAR Archive:(mysql-5.7.25-el7-x86_64.tar.gz)
    2)使用Linux - Generic
    Select Version:5.7.25
    Select Operating System:Linux - Generic
    Select OS Version:Linux - Generic (glibc 2.12) (x86, 64-bit)
    列表中下载:
    Compressed TAR Archive:(mysql-5.7.25-linux-glibc2.12-x86_64.tar.gz)【本文中使用的是这个版本】
    注意:上边两种方式找mysql离线安装包的方式都可以。

    五、上传第四步下载的mysql TAR包

    将下载的二进制压缩包放到/usr/local/目录下。
    解压安装包
    tar -zxvf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz

    将解压好的文件夹重命名为mysql

    mv mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz mysql

    六、在etc下新建配置文件my.cnf,并在该文件内添加以下代码:

    复制代码
    [mysql]
    # 设置mysql客户端默认字符集
    default-character-set=utf8
    socket=/var/lib/mysql/mysql.sock
    [mysqld]
    skip-name-resolve
    #设置3306端口
    port=3306
    socket=/var/lib/mysql/mysql.sock
    # 设置mysql的安装目录
    basedir=/usr/local/mysql
    # 设置mysql数据库的数据的存放目录
    datadir=/usr/local/mysql/data
    # 允许最大连接数
    max_connections=200
    # 服务端使用的字符集默认为8比特编码的latin1字符集
    character-set-server=utf8
    # 创建新表时将使用的默认存储引擎
    default-storage-engine=INNODB
    lower_case_table_names=1
    max_allowed_packet=16M

    七、创建步骤六中用到的目录并将其用户设置为mysql

    mkdir /var/lib/mysql
    mkdir /var/lib/mysql/mysql
    chown -R mysql:mysql /var/lib/mysql
    chown -R mysql:mysql /var/lib/mysql/mysql

    八、安装mysql软件

    cd /usr/local/mysql
    mkdir data
    chown -R mysql:mysql ./   #修改当前目录拥有者为mysql用户
    ./bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data/

    到此数据库安装完成!

    九、mysql其他配置

    授予my.cnf的最大权限。

    chown 777 /etc/my.cnf

    复制启动脚本到资源目录

    cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld 
    #如果没有rc.d直接输入/etc/init.d/mysqld即可

    增加mysqld服务控制脚本执行权限

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

    将mysqld服务加入到系统服务

    chkconfig --add mysqld

    检查mysqld服务是否已经生效

    chkconfig --list mysqld

    命令输出类似下面的结果:

    mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    表明mysqld服务已经生效,在2、3、4、5运行级别随系统启动而自动启动,以后可以使用service命令控制mysql的启动和停止。


    启动msql(停止mysqld服务:service mysqld stop)

    service mysqld start

    将mysql的bin目录加入PATH环境变量,编辑/etc/profile文件

    vi /etc/profile

    在文件最后添加如下信息:

    export PATH=$PATH:/usr/local/mysql/bin


    执行下面的命令使所做的更改生效:

    source /etc/profile

    十、以root账户登陆mysql

    #通过cat /root/.mysql_secret获取初始密码
    mysql -u root -p

    修改密码

    复制代码
    [root@CDH-141 mysql]# mysql -uroot -p
    Enter password: #此处填写上边获取到的初始密码‘poc3u0mO_luv’
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.25
    
    Copyright (c) 2000, 2015, 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>  set PASSWORD = PASSWORD('123456');
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit
    Bye

    方法二:

    设置root账户密码 注意下面的you password改成你的要修改的密码

    use mysql;
    update user set password=password('you password') where user='root'and host='localhost';

    十一、添加远程访问权限

    复制代码
    # 添加远程访问权限
    mysql> use mysql
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> update user set host='%' where user='root';
    Query OK, 1 row affected (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 0
    
    mysql> select host,user from user;
    +-----------+---------------+
    | host      | user          |
    +-----------+---------------+
    | %         | root          |
    | localhost | mysql.session |
    | localhost | mysql.sys     |
    +-----------+---------------+
    3 rows in set (0.00 sec)
    
    mysql> 
    复制代码

    方法二:

    设置远程主机登录,注意下面的your username 和 your password改成你需要设置的用户和密码

    GRANT ALL PRIVILEGES ON *.* TO'your username'@'%' IDENTIFIED BY 'your password' WITH GRANT OPTION;
    FLUSH PRIVILEGES ;

    十二、重启mysql生效

    # 重启mysql
    [root@CDH-141 mysql]# /etc/init.d/mysqld restart
    Shutting down MySQL..[  OK  ]
    Starting MySQL..[  OK  ]
    [root@CDH-141 mysql]# 
  • 相关阅读:
    《Selenium自动化测试实战》新书上市,有需要朋友们可以了解下,欢迎大家多提宝贵意见
    OrchardCore 如何动态加载模块?
    性能测试基础知识体系
    职场新人如何快速融入团队
    技术之外的工程师另类成长指南
    4.17-线上-技术沙龙问题汇总答疑
    3.20-上海-技术沙龙问题汇总答疑
    推荐书单4.0:测试工程师破局之路
    从技术专家到技术管理,我对管理的思考
    chrome打开本地链接
  • 原文地址:https://www.cnblogs.com/mergy/p/14078413.html
Copyright © 2020-2023  润新知