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;