linux(centos)之yum安装mysql

==官网==
www.mysql.com
www.oracle.com

==准备工作==
环境:# 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/


后附部分官网提示图

linux(centos)之yum安装mysql

linux(centos)之yum安装mysql

linux(centos)之yum安装mysql