Linux通過rpm包安裝mysql5.7.22

準備工作:
1.首先登陸mysql官網下載頁面
https://dev.mysql.com/downloads/mysql/5.7.html#downloads
2.選擇相應的選項並下載rpm包
Select Version:5.7.22
Select Operating System:Red Hat Enterprise Linux / Oracle Linux
Select OS Version:Red Hat Enterprise Linux 7/ Oracle Linux 7 (x86,64-bit)
選擇完畢在下方選擇mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar下載
3.安裝系統

[root@zk1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.2 (Maipo)
[root@zk1 ~]#

1.上傳並解壓rpm包

[root@zk1 opt]#mkdir mysql
[root@zk1 opt]#mv mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar ./mysql
[root@zk1 opt]#cd mysql/
[root@zk1 mysql]#tar -xvf mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
[root@zk1 mysql]#ll
total 1168028
-rw-r--r-- 1 root root  598026240 Mar  5 10:44 mysql-5.7.22-1.el7.x86_64.rpm-bundle.tar
-rw-r--r-- 1 7155 31415  25106088 Mar  5 10:24 mysql-community-client-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415    280800 Mar  5 10:24 mysql-community-common-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   3781636 Mar  5 10:24 mysql-community-devel-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  46742952 Mar  5 10:24 mysql-community-embedded-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  24078476 Mar  5 10:24 mysql-community-embedded-compat-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 129955496 Mar  5 10:24 mysql-community-embedded-devel-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2239868 Mar  5 10:24 mysql-community-libs-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415   2116356 Mar  5 10:24 mysql-community-libs-compat-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  55743828 Mar  5 10:24 mysql-community-minimal-debuginfo-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 172992596 Mar  5 10:25 mysql-community-server-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415  15255560 Mar  5 10:25 mysql-community-server-minimal-5.7.22-1.el7.x86_64.rpm
-rw-r--r-- 1 7155 31415 119716756 Mar  5 10:25 mysql-community-test-5.7.22-1.el7.x86_64.rpm

2.刪除maridb

[root@zk1 mysql]#rpm -qa | grep mariadb
mariadb-libs-5.5.44-2.el7.centos.x86_64
[root@zk1 mysql]#rpm -e --nodeps mariadb-libs-5.5.44-2.el7.centos.x86_64

3.由於有依賴關係,依次安裝以下四個包

[root@zk1 mysql]#rpm -ivh mysql-community-common-5.7.22-1.el7.x86_64.rpm
[root@zk1 mysql]#rpm -ivh mysql-community-libs-5.7.22-1.el7.x86_64.rpm
[root@zk1 mysql]#rpm -ivh mysql-community-client-5.7.22-1.el7.x86_64.rpm
[root@zk1 mysql]#rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.22-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
error: Failed dependencies:
        /usr/bin/perl is needed by mysql-community-server-5.7.22-1.el7.x86_64
        net-tools is needed by mysql-community-server-5.7.22-1.el7.x86_64
        perl(Getopt::Long) is needed by mysql-community-server-5.7.22-1.el7.x86_64
        perl(strict) is needed by mysql-community-server-5.7.22-1.el7.x86_64

#依賴報錯安裝相應的包
[root@zk1 mysql]#yum install net-tools
[root@zk1 mysql]#yum install perl
#依賴包安裝完成在繼續安裝剛纔報錯rpm包
[root@zk1 mysql]#rpm -ivh mysql-community-server-5.7.22-1.el7.x86_64.rpm

4.啓動mysql

[root@zk1 mysql]#service mysqld start
#獲取密碼
[root@zk1 usr]#grep 'temporary password' /var/log/mysqld.log
2018-07-28T08:03:36.165230Z 1 [Note] A temporary password is generated for root@localhost: Zc?H2OJE65ub
#登陸mysql
[root@zk1 usr]#mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22

Copyright (c) 2000, 2018, 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>
#更改root密碼
mysql> set password=password('tianpy5@');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
#由於密碼簡單,不符合策略,改爲包含字母和數字,大小寫,特殊字符的字符串
mysql>  set password=password('Tian_0801');
#授權訪問
mysql> grant all privileges on *.* to root@'%' identified by 'Tian_0801';
mysql> flush privileges;

5.配置文件修改字符編碼

[root@zk1 ~]# cat /etc/my.cnf
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
character_set_server=utf8
collation-server=utf8_general_ci

[mysql]
default-character-set=utf8

[client]
default-character-set=utf8

6.設置開機自啓動,並重啓mysql

[root@zk1 ~]# systemctl enable mysqld
[root@zk1 ~]# systemctl restart mysqld
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章