1. 程式人生 > >mysql之yum安裝

mysql之yum安裝

==準備工作== 環境:# cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core)

適當調整記憶體

關閉selinux

# sed -ri '/^SELINUX=/c\SELINUX=disabled' /etc/selinux/config(vim /etc/selinux/config更改也可) # setenforce 0

關閉防火牆

# systemctl stop firewalld && systemctl disable firewalld

1. 新增yum倉庫 # cd /etc//yum.repos.d/

# vim mysql.repo

# Enable to use MySQL 5.7 [mysql57-community] name=MySQL 5.7 Community Server baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/  #官方源地址 enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

此處需要有校驗檔案,否則安裝會報如下錯誤:

Downloading packages: 警告:/var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.23-1.el7.x86_64.rpm: 頭V3 DSA/SHA1 Signature, 金鑰 ID 5072e1f5: NOKEY 從 file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql 檢索金鑰

獲取 GPG 金鑰失敗:[Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"

解決辦法:

A. 到mysql官網下載校驗檔案

B. 跳過校驗,編輯檔案/etc/yum.repos.d/mysql.repo

修改gpgcheck=0

註釋或這刪除gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

2. 重新整理yum倉庫 # yum clean all # yum makecache

[[email protected]~]# yum repolist 已載入外掛:fastestmirror, langpacks Loading mirror speeds from cached hostfile 源標識                                    源名稱                                                           狀態 base/7/x86_64                             CentOS-7 - Base - 163.com                                         9,911 epel/x86_64                               Extra Packages for Enterprise Linux 7 - x86_64                   12,685 extras/7/x86_64                           CentOS-7 - Extras - 163.com                                         402 mysql57-community/x86_64                  MySQL 5.7 Community Server                                          287 updates/7/x86_64                          CentOS-7 - Updates - 163.com                                      1,336 repolist: 24,621

3. 安裝mysql-server 查詢安裝包: # yum list | grep mysql-community-server

mysql-community-server.x86_64           5.7.23-1.el7                   mysql57-community

安裝mysql: # yum -y install mysql-community-server.x86_64

......

已安裝: mysql-community-libs.x86_64 0:5.7.23-1.el7                         mysql-community-libs-compat.x86_64 0:5.7.23-1.el7                         mysql-community-server.x86_64 0:5.7.23-1.el7                        

作為依賴被安裝: mysql-community-client.x86_64 0:5.7.23-1.el7                             mysql-community-common.x86_64 0:5.7.23-1.el7                             numactl-libs.x86_64 0:2.0.9-7.el7                            

替代: mariadb-libs.x86_64 1:5.5.56-2.el7                                                                                                                                                                        

完畢!

4. 啟動資料庫,並設定開機自啟

[[email protected] ~]# systemctl enable mysqld && systemctl start mysqld

[[email protected] ~]# ls /var/lib/mysql auto.cnf    ca.pem           client-key.pem  ibdata1      ib_logfile1  mysql       mysql.sock.lock     private_key.pem  server-cert.pem  sys ca-key.pem  client-cert.pem  ib_buffer_pool  ib_logfile0  ibtmp1       mysql.sock  performance_schema  public_key.pem   server-key.pem

[[email protected] ~]# systemctl status mysqld ● mysqld.service - MySQL Server    Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)    Active: active (running) since.....

......

5. 登陸mysql

[[email protected] ~]# grep 'password' /var/log/mysqld.log  #查詢登陸密碼,預設初始密碼(密碼需要自己查詢) 2018-09-15T07:30:15.267136Z 1 [Note] A temporary password is generated for [email protected]: weeh9=n8ts7K [[email protected] ~]# mysql -u root -p'weeh9=n8ts7K' mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor.  Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.23

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>

看見mysql>提示符,說明登陸成功。

修改root密碼:

mysql>  ALTER USER 'root'@'localhost' IDENTIFIED BY '[email protected]'; Query OK, 0 rows affected (0.00 sec)

實際生產中,需要新增對應的服務資料庫賬戶,並設定禁止登陸系統,以及授予所需許可權

重新整理許可權:

mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)

檢視資料庫:

mysql> show databases; +--------------------+ | Database           | +--------------------+ | information_schema | | mysql              | | performance_schema | | sys                | +--------------------+ 4 rows in set (0.00 sec)

退出資料庫:

mysql> exit; Bye

至此,yum安裝mysql5.7完成!

==錯誤提示== 1. 記憶體不足(>1G):增加記憶體 2. 磁碟空間不足:新增磁碟 pvcreate vgextend vg /dev/... lvextend -L +5G xfs_growfs /dev/

後附部分官網提示圖