zoukankan      html  css  js  c++  java
  • RHEL7.3安装mysql5.7

    RHEL7.3 install mysql5.7

    CentOS7默认安装MariaDB而不是MySQL,而且yum服务器上也移除了MySQL相关的软件包。
    因为MariaDB和MySQL可能会冲突,需先卸载MariaDB。

    1、卸载MariaDB, 安装新版mysql之前需要将系统自带的mariadb-lib卸载
    [root@localhost mysql]# rpm -qa | grep -i mariadb
    mariadb-libs-5.5.52-1.el7.x86_64
    [root@localhost mysql]# rpm -e --nodeps mariadb-libs-5.5.52-1.el7.x86_64

    2、下载mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar安装包,下载地址为:https://dev.mysql.com/downloads/file/?id=469456

    3、上传mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar到linux服务器,并解压tar包。
    由于下载的是.tar包,解压的时用-xvf,而-zxvf是解压.tar.gz的。

    解压:[root@localhost mysql]#tar -xvf mysql-5.7.18-1.el7.x86_64.rpm-bundle.tar
    mysql-community-server-5.7.18-1.el7.x86_64.rpm
    mysql-community-embedded-devel-5.7.18-1.el7.x86_64.rpm
    mysql-community-devel-5.7.18-1.el7.x86_64.rpm
    mysql-community-client-5.7.18-1.el7.x86_64.rpm
    mysql-community-common-5.7.18-1.el7.x86_64.rpm
    mysql-community-embedded-5.7.18-1.el7.x86_64.rpm
    mysql-community-embedded-compat-5.7.18-1.el7.x86_64.rpm
    mysql-community-libs-5.7.18-1.el7.x86_64.rpm
    mysql-community-server-minimal-5.7.18-1.el7.x86_64.rpm
    mysql-community-test-5.7.18-1.el7.x86_64.rpm
    mysql-community-minimal-debuginfo-5.7.18-1.el7.x86_64.rpm
    mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm

    4、新建mysql用户
    [root@rhel75 /]# groupadd mysql
    [root@rhel75 /]# useradd -r -g mysql -p root mysql
    [root@rhel75 /]# usermod -s /sbin/nologin mysql

    5、使用rpm -ivh命令进行安装,安装的时候一定要注意先后顺序,因为有顺序依赖,必须按照顺序来安装。
    [root@localhost mysql]# rpm -ivh mysql-community-common-5.7.18-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-libs-5.7.18-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-libs-compat-5.7.18-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-devel-5.7.18-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-client-5.7.18-1.el7.x86_64.rpm
    [root@localhost mysql]# rpm -ivh mysql-community-server-5.7.18-1.el7.x86_64.rpm

    6、 数据库初始化
    为了保证数据库目录为与文件的所有者为mysql用户,以root身份运行mysql服务需要执行--user=mysql选项命令初始化
    [root@localhost mysql]# mysqld --initialize --user=mysql 此处是第4步新建的mysql用户
    使用的 --initialize 初始化的,会生成一个mysql数据库的root账户密码,密码在log文件里(红色标示)

    [root@localhost mysql]# cat /var/log/mysqld.log
    2017-06-24T16:47:12.709474Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
    2017-06-24T16:47:12.590590Z 0 [Warning] InnoDB: New log files created, LSN=45790
    2017-06-24T16:47:12.000269Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
    2017-06-24T16:47:12.109868Z 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: 960c533e-49fb-11e7-91f2-00163e089fd2.
    2017-06-24T16:47:12.116186Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
    2017-06-24T16:47:12.116777Z 1 [Note] A temporary password is generated for root@localhost: :qqeftsut3wj

    7、启动和停止数据库
    查看MySQL状态
    [root@rhel75 /]# systemctl status mysqld

    启动MySQL
    [root@rhel75 /]# systemctl start mysqld

    开机启动MySQL
    [root@rhel75 /]# systemctl enable mysqld

    第一次安装后设置修改密码
    [root@rhel75 /]# mysql_secure_installation

    针对已设置过root密码的修改
    mysql> use mysql;
    mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';
    mysql> flush privileges;

    8、修改my.cnf配置文件
    vi /etc/my.cnf
    如果文件中有bind-address = 127.0.0.1而且前面没有#注释进行下面的步骤
    注释掉#bind-address = 127.0.0.1,如果没有就不用修改。
    然后重启mysql

    9、关闭防火墙
    Centos7中防火墙变为了firewall,所以千万不要在使用iptable去关闭了。

    1 查看防火墙状态
    [root@localhost mysql]# firewall-cmd --state
    running

    2 然后关闭防火墙
    [root@localhost mysql]# systemctl stop firewalld

    10、连接数据库,进行设置
    [root@localhost mysql]# mysql -u root -p
    Enter password:
    修改密码:set password = password('你的密码');

    添加Mysql用户并赋予权限
    mysql> CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;
    mysql> GRANT ALL ON zabbix.* TO zabbix@'localhost' IDENTIFIED BY 'zabbix';
    mysql> flush privileges;

     

  • 相关阅读:
    adb shell下sqlite:not found
    Intent 获取视频,音频等
    android手机信息采集
    Multiple substitutions specified in nonpositional format; did you mean to add the formatted="false" attribute?
    android 源代码在线地址
    MediaScanner生成及保存thumbnail的方式
    android-pc截屏
    Oracle 巡检中的Oracle 错误
    Oracle 也来谈谈分页
    烦人的项目 OBIEE升级
  • 原文地址:https://www.cnblogs.com/raykuan/p/6917164.html
Copyright © 2011-2022 走看看