Linxu安裝mysql

1.確保你的虛擬機能上網mysql

2.咱們使用的時yum安裝的 下載mysql的repo源sql

鍵入以下命令:數據庫

$ wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
[root@slave1 ~]# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
--2018-03-15 15:38:59--  http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
正在解析主機 repo.mysql.com (repo.mysql.com)... 23.207.113.116
正在鏈接 repo.mysql.com (repo.mysql.com)|23.207.113.116|:80... 已鏈接。
已發出 HTTP 請求,正在等待迴應... 200 OK
長度:6140 (6.0K) [application/x-redhat-package-manager]
正在保存至: 「mysql-community-release-el7-5.noarch.rpm」

100%[==============================================>] 6,140       --.-K/s 用時 0s      

2018-03-15 15:38:59 (293 MB/s) - 已保存 「mysql-community-release-el7-5.noarch.rpm」 [6140/6140])

返回200 Ok說明成功centos

3.安裝mysql-community-release-el7-5.noarch.rpm包架構

$ sudo rpm -ivh mysql-community-release-el7-5.noarch.rpmoracle

[root@slave1 ~]# sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
準備中...                          ################################# [100%]
正在升級/安裝...
   1:mysql-community-release-el7-5    ################################# [100%]

安裝這個包後,會得到兩個mysql的yum repo源:/etc/yum.repos.d/mysql-community.repo,/etc/yum.repos.d/mysql-community-source.repo。app

4.安裝mysqlsocket

$ sudo yum install mysql-serverui

根據提示安裝就能夠了,不過安裝完成後沒有密碼,須要重置密碼this

安裝過程當中可能會出現以下錯誤:

[root@slave1 ~]# sudo yum install mysql-server
已加載插件:fastestmirror, langpacks
/var/run/yum.pid 已被鎖定,PID 爲 3761 的另外一個程序正在運行。
Another app is currently holding the yum lock; waiting for it to exit...
  另外一個應用程序是:PackageKit
    內存:114 M RSS (450 MB VSZ)
    已啓動: Thu Mar 15 15:38:40 2018 - 00:59以前
    狀態  :睡眠中,進程ID:3761
Another app is currently holding the yum lock; waiting for it to exit...
  另外一個應用程序是:PackageKit
    內存:114 M RSS (450 MB VSZ)
    已啓動: Thu Mar 15 15:38:40 2018 - 01:01以前
    狀態  :運行中,進程ID:3761

解決辦法 你看到這個進程ID 3761

用以下命令:kill -9 強制殺死該命令

[root@slave1 ~]# kill -9 3761

若是問題沒有解決多來幾回就行了

以下安裝中:#############   0.1%

[root@slave1 ~]# sudo yum install mysql-server
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.bit.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解決依賴關係
--> 正在檢查事務
---> 軟件包 mysql-community-server.x86_64.0.5.6.39-2.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-common(x86-64) = 5.6.39-2.el7,它被軟件包 mysql-community-server-5.6.39-2.el7.x86_64 須要
--> 正在處理依賴關係 mysql-community-client(x86-64) >= 5.6.10,它被軟件包 mysql-community-server-5.6.39-2.el7.x86_64 須要
--> 正在處理依賴關係 perl(DBI),它被軟件包 mysql-community-server-5.6.39-2.el7.x86_64 須要
--> 正在檢查事務
---> 軟件包 mysql-community-client.x86_64.0.5.6.39-2.el7 將被 安裝
--> 正在處理依賴關係 mysql-community-libs(x86-64) >= 5.6.10,它被軟件包 mysql-community-client-5.6.39-2.el7.x86_64 須要
---> 軟件包 mysql-community-common.x86_64.0.5.6.39-2.el7 將被 安裝
---> 軟件包 perl-DBI.x86_64.0.1.627-4.el7 將被 安裝
--> 正在處理依賴關係 perl(RPC::PlServer) >= 0.2001,它被軟件包 perl-DBI-1.627-4.el7.x86_64 須要
--> 正在處理依賴關係 perl(RPC::PlClient) >= 0.2000,它被軟件包 perl-DBI-1.627-4.el7.x86_64 須要
--> 正在檢查事務
---> 軟件包 mariadb-libs.x86_64.1.5.5.41-2.el7_0 將被 取代
---> 軟件包 mysql-community-libs.x86_64.0.5.6.39-2.el7 將被 捨棄
---> 軟件包 perl-PlRPC.noarch.0.0.2020-14.el7 將被 安裝
--> 正在處理依賴關係 perl(Net::Daemon) >= 0.13,它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 須要
--> 正在處理依賴關係 perl(Net::Daemon::Test),它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 須要
--> 正在處理依賴關係 perl(Net::Daemon::Log),它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 須要
--> 正在處理依賴關係 perl(Compress::Zlib),它被軟件包 perl-PlRPC-0.2020-14.el7.noarch 須要
--> 正在檢查事務
---> 軟件包 perl-IO-Compress.noarch.0.2.061-2.el7 將被 安裝
--> 正在處理依賴關係 perl(Compress::Raw::Zlib) >= 2.061,它被軟件包 perl-IO-Compress-2.061-2.el7.noarch 須要
--> 正在處理依賴關係 perl(Compress::Raw::Bzip2) >= 2.061,它被軟件包 perl-IO-Compress-2.061-2.el7.noarch 須要
---> 軟件包 perl-Net-Daemon.noarch.0.0.48-5.el7 將被 安裝
--> 正在檢查事務
---> 軟件包 perl-Compress-Raw-Bzip2.x86_64.0.2.061-3.el7 將被 安裝
---> 軟件包 perl-Compress-Raw-Zlib.x86_64.1.2.061-4.el7 將被 安裝
--> 解決依賴關係完成

依賴關係解決

========================================================================================
 Package                     架構       版本                源                     大小
========================================================================================
正在安裝:
 mysql-community-libs        x86_64     5.6.39-2.el7        mysql56-community     2.0 M
      替換  mariadb-libs.x86_64 1:5.5.41-2.el7_0
 mysql-community-server      x86_64     5.6.39-2.el7        mysql56-community      59 M
爲依賴而安裝:
 mysql-community-client      x86_64     5.6.39-2.el7        mysql56-community      19 M
 mysql-community-common      x86_64     5.6.39-2.el7        mysql56-community     257 k
 perl-Compress-Raw-Bzip2     x86_64     2.061-3.el7         base                   32 k
 perl-Compress-Raw-Zlib      x86_64     1:2.061-4.el7       base                   57 k
 perl-DBI                    x86_64     1.627-4.el7         base                  802 k
 perl-IO-Compress            noarch     2.061-2.el7         base                  260 k
 perl-Net-Daemon             noarch     0.48-5.el7          base                   51 k
 perl-PlRPC                  noarch     0.2020-14.el7       base                   36 k

事務概要
========================================================================================
安裝  2 軟件包 (+8 依賴軟件包)

總下載量:82 M
Is this ok [y/d/N]: y
Downloading packages:
警告:/var/cache/yum/x86_64/7/mysql56-community/packages/mysql-community-common-5.6.39-2.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 密鑰 ID 5072e1f5: NOKEY
mysql-community-common-5.6.39-2.el7.x86_64.rpm 的公鑰還沒有安裝
(1/10): mysql-community-common-5.6.39-2.el7.x86_64.rpm           | 257 kB  00:00:00     
(2/10): mysql-community-libs-5.6.39-2.el7.x86_64.rpm             | 2.0 MB  00:00:00     
警告:/var/cache/yum/x86_64/7/base/packages/perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm: 頭V3 RSA/SHA256 Signature, 密鑰 ID f4a80eb5: NOKEY
perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm 的公鑰還沒有安裝
(3/10): perl-Compress-Raw-Zlib-2.061-4.el7.x86_64.rpm            |  57 kB  00:00:00     
(4/10): perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64.rpm           |  32 kB  00:00:00     
(5/10): perl-DBI-1.627-4.el7.x86_64.rpm                          | 802 kB  00:00:02     
(6/10): perl-Net-Daemon-0.48-5.el7.noarch.rpm                    |  51 kB  00:00:00     
(7/10): perl-PlRPC-0.2020-14.el7.noarch.rpm                      |  36 kB  00:00:00     
(8/10): perl-IO-Compress-2.061-2.el7.noarch.rpm                  | 260 kB  00:00:04     
(9/10): mysql-community-client-5.6.39-2.el7.x86_64.rpm           |  19 MB  00:00:09     
(10/10): mysql-community-server-5.6.39-2.el7.x86_64.rpm          |  59 MB  00:00:32     
----------------------------------------------------------------------------------------
總計                                                       2.4 MB/s |  82 MB  00:34     
從 file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 檢索密鑰
導入 GPG key 0x5072E1F5:
 用戶ID     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 指紋       : a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 軟件包     : mysql-community-release-el7-5.noarch (installed)
 來自       : file:/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
是否繼續?[y/N]:y
從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 檢索密鑰
導入 GPG key 0xF4A80EB5:
 用戶ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指紋       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 軟件包     : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda)
 來自       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
是否繼續?[y/N]:y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 數據庫已被非 yum 程序修改。
  正在安裝    : mysql-community-common-5.6.39-2.el7.x86_64                         1/11 
  正在安裝    : mysql-community-libs-5.6.39-2.el7.x86_64                           2/11 
  正在安裝    : mysql-community-client-5.6.39-2.el7.x86_64                         3/11 
  正在安裝    : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                        4/11 
  正在安裝    : perl-Net-Daemon-0.48-5.el7.noarch                                  5/11 
  正在安裝    : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                         6/11 
  正在安裝    : perl-IO-Compress-2.061-2.el7.noarch                                7/11 
  正在安裝    : perl-PlRPC-0.2020-14.el7.noarch                                    8/11 
  正在安裝    : perl-DBI-1.627-4.el7.x86_64                                        9/11 
  正在安裝    : mysql-community-server-5.6.39-2.el7.x86_64                        10/11 
  正在刪除    : 1:mariadb-libs-5.5.41-2.el7_0.x86_64                              11/11 
  驗證中      : mysql-community-server-5.6.39-2.el7.x86_64                         1/11 
  驗證中      : perl-Compress-Raw-Bzip2-2.061-3.el7.x86_64                         2/11 
  驗證中      : perl-Net-Daemon-0.48-5.el7.noarch                                  3/11 
  驗證中      : mysql-community-common-5.6.39-2.el7.x86_64                         4/11 
  驗證中      : mysql-community-libs-5.6.39-2.el7.x86_64                           5/11 
  驗證中      : mysql-community-client-5.6.39-2.el7.x86_64                         6/11 
  驗證中      : 1:perl-Compress-Raw-Zlib-2.061-4.el7.x86_64                        7/11 
  驗證中      : perl-PlRPC-0.2020-14.el7.noarch                                    8/11 
  驗證中      : perl-IO-Compress-2.061-2.el7.noarch                                9/11 
  驗證中      : perl-DBI-1.627-4.el7.x86_64                                       10/11 
  驗證中      : 1:mariadb-libs-5.5.41-2.el7_0.x86_64                              11/11 

已安裝:
  mysql-community-libs.x86_64 0:5.6.39-2.el7                                            
  mysql-community-server.x86_64 0:5.6.39-2.el7                                          

做爲依賴被安裝:
  mysql-community-client.x86_64 0:5.6.39-2.el7                                          
  mysql-community-common.x86_64 0:5.6.39-2.el7                                          
  perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7                                          
  perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7                                           
  perl-DBI.x86_64 0:1.627-4.el7                                                         
  perl-IO-Compress.noarch 0:2.061-2.el7                                                 
  perl-Net-Daemon.noarch 0:0.48-5.el7                                                   
  perl-PlRPC.noarch 0:0.2020-14.el7                                                     

替代:
  mariadb-libs.x86_64 1:5.5.41-2.el7_0                                                  

完畢!

直至提示安裝完畢就行了

5.重置mysql密碼

登陸時有可能報這樣的錯:ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘ (2),緣由是/var/lib/mysql的訪問權限問題。下面的命令把/var/lib/mysql的擁有者改成當前用戶:
$ sudo chown -R root:root /var/lib/mysql

[root@slave1 ~]# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@slave1 ~]# sudo chown -R root:root /var/lib/mysql

6.重啓mysql服務

$ service mysqld restart

[root@slave1 ~]# service mysqld restart
Redirecting to /bin/systemctl restart  mysqld.service

7.再次登錄

[root@slave1 ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.39 MySQL Community Server (GPL)

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> use mysql

登錄成功

8.接下來登陸重置密碼

$ mysql -u root //直接回車進入mysql控制檯
mysql > use mysql;
mysql > update user set password=password('root') where user='root';
mysql > exit;

注意分號結尾

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set password=password('root') where user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4  Changed: 4  Warnings: 0

mysql> exit
Bye

9.試着建立一個數據庫

mysql> create database school;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| school             |
+--------------------+
4 rows in set (0.00 sec)

10.其餘

Linux下配置Mysql容許遠程訪問詳解

操做很是簡單,就5步驟,以下:
1.進入 mysql:
/usr/local/mysql/bin/mysql -u root -p
2.使用 mysql庫 :
use mysql;
3.查看用戶表 :
SELECT `Host`,`User` FROM user;
4.更新用戶表 :
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
5.強制刷新權限 :
flush privileges;
完成以上步驟便可遠程鏈接數據庫了,上邊關鍵的一句是
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
其中%的意思是容許全部的ip遠程訪問,若是須要指定具體的某個ip就寫上具體的ip便可 
KO...
相關文章
相關標籤/搜索