RHEL7.3安装mysql5.7

RHEL7.3 install mysql5.7node

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

一、卸载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_64linux

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

三、上传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服务器

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

五、使用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.rpmspa

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

[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: :qqeftsut3wjserver

七、启动和中止数据库
查看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;

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

九、关闭防火墙
Centos7中防火墙变为了firewall,因此千万不要在使用iptable去关闭了。

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

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

十、链接数据库,进行设置
[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;

相关文章
相关标签/搜索