MySQL5.7 安裝 - Linux下RPM方式安裝

目前MySQL5.7的最新版本是5.7.19,

下載

安裝

我已經把安裝包放到/usr/local/software路徑下面

[root@localhost software]# ls
mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
  • 1
  • 2

查看是否已經安裝mysql

rpm -qa | grep mysql
  • 1

解壓tar文件

  • 命令
tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar
  • 1
  • 執行結果
[root@localhost software]# tar -xvf mysql-5.7.19-1.el7.x86_64.rpm-bundle.tar 
mysql-community-embedded-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm
mysql-community-test-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-minimal-debuginfo-5.7.19-1.el7.x86_64.rpm
mysql-community-server-minimal-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.19-1.el7.x86_64.rpm
mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-embedded-5.7.19-1.el7.x86_64.rpm
mysql-community-devel-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

卸載衝突的RPM組件

在我們安裝mysql相關組件的時候,如果不將此衝突的組件刪除掉,我們是安裝不成功的。
我們可以先跳過這步,直接進入下步操作,在安裝的過程中會有相應的提示。下面是我所碰到的一個提示:

# 安裝mysql組件時出現的依賴錯誤
error: Failed dependencies:
        mysql-community-common(x86-64) >= 5.7.9 is needed by mysql-community-libs-5.7.19-1.el7.x86_64
        mariadb-libs is obsoleted by mysql-community-libs-5.7.19-1.el7.x86_64

# 卸載mariadb-libs時出現的依賴錯誤
error: Failed dependencies:
        libmysqlclient.so.18()(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
        libmysqlclient.so.18(libmysqlclient_18)(64bit) is needed by (installed) postfix-2:2.10.1-6.el7.x86_64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

可以看出,我們需要卸載postfixmariadb-libs相關的組件。卸載我們可以使用rpm -ev xxx

  • 查看postfixmariadb-libs
rpm -qa | grep postfix
rpm -qa | grep mariadb
  • 1
  • 2
  • 執行過程
[root@localhost software]# rpm -qa | grep postfix
postfix-2.10.1-6.el7.x86_64

[root@localhost software]# rpm -qa | grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 卸載postfixmariadb-libs
rpm -ev postfix-2.10.1-6.el7.x86_64
rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
  • 1
  • 2
  • 執行過程
[root@localhost software]# rpm -ev postfix-2.10.1-6.el7.x86_64
Preparing packages...
postfix-2:2.10.1-6.el7.x86_64
[root@localhost software]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64
Preparing packages...
mariadb-libs-1:5.5.52-1.el7.x86_64
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

安裝依賴組件

在我進行安裝msql-community-server-xxx的時候出現了下面的問題

[root@localhost software]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-server-5.7.19-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.19-1.el7.x86_64
        libaio.so.1()(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        libaio.so.1(LIBAIO_0.1)(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        libaio.so.1(LIBAIO_0.4)(64bit) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        net-tools is needed by mysql-community-server-5.7.19-1.el7.x86_64
        perl(Getopt::Long) is needed by mysql-community-server-5.7.19-1.el7.x86_64
        perl(strict) is needed by mysql-community-server-5.7.19-1.el7.x86_64
[root@localhost software]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

由上面的錯誤可以看出我們需要安裝相應的依賴
1. libaio
2. net-tools
3. perl

  • 安裝依賴
yum -y install libaio
yum -y net-tools
yum -y perl
  • 1
  • 2
  • 3

安裝mysql組件

經過上面的解壓操作,我們得到了很多rpm文件。但是我們不需要這麼多,我們只需要安裝一下四個組件就可以了:

mysql-community-common-5.7.19-1.el7.x86_64.rpm
mysql-community-libs-5.7.19-1.el7.x86_64.rpm
mysql-community-client-5.7.19-1.el7.x86_64.rpm
mysql-community-server-5.7.19-1.el7.x86_64.rpm

因爲具有依賴關係,所以我們需要按順序執行。
rpm -ivh 文件名就能安裝相應的組件。
在執行server的時候,需要依賴安裝一些工具組件,已經在上文有說明了

  • 安裝命令
rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm --nodeps
  • 1
  • 2
  • 3
  • 4
  • 執行過程
[root@localhost software]# rpm -ivh mysql-community-common-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-common-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.19-1.e################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-libs-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-libs-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.19-1.el7################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-client-5.7.19-1.el7.x86_64.rpm 
warning: mysql-community-client-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.19-1.e################################# [100%]
[root@localhost software]# rpm -ivh mysql-community-server-5.7.19-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.19-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.19-1.e################################# [100%]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

啓動數據庫

# 查看mysql是否啓動
service mysqld status

# 啓動mysql
service mysqld start

# 停止mysql
service mysqld stop

# 重啓mysql
service mysqld restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

修改密碼

mysql安裝完成之後我們是沒有設置密碼的,但是mysql爲我們設置了一個臨時的密碼,我們可以查看mysql的日誌知道這個臨時密碼。

  • 查看臨時密碼
grep password /var/log/mysqld.log
  • 1
  • 執行過程
[root@localhost ~]# grep password /var/log/mysqld.log 
2017-09-01T16:43:10.889769Z 1 [Note] A temporary password is generated for root@localhost: hcLMTxbOh2?w
  • 1
  • 2

這樣我們得知臨時密碼是:hcLMTxbOh2?w
然後我們用這個臨時密碼登錄數據庫。

數據庫的密碼需要滿足以下條件:大小寫字母,數字和特殊符號

  • 執行命令
# 登錄mysql,之後需要輸入密碼
mysql -p

# 設置新密碼
set password = password("Mysql_123456");

# 退出當前登錄
quit;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 執行過程
[root@localhost ~]# mysql -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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("Mysql_123456");
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> quit;
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

重新登錄,這樣我們就能用新的密碼登錄了。我們可以愉快的進行數據庫操作了。

================================================================

mysql的配置文件修改屬性

character_set_server=utf8       ----服務器字符編碼
lower_case_table_names=1     -----表名不區分大小寫

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章