centos7下yum安装mysql8

// 安装之前查看mysql是否存在

[root@localhost ~]# rpm -qa | grep -i mysql
mysql-community-common-8.0.13-1.el7.x86_64
mysql80-community-release-el7-1.noarch


// 移除

[root@localhost ~]# yum remove mysql-community-release
已加载插件:fastestmirror, langpacks
参数 mysql-community-release 没有匹配
不删除任何软件包


// 安装之前查看mysql是否存在

[root@localhost ~]# rpm -qa | grep -i mysql           
mysql-community-common-8.0.13-1.el7.x86_64
mysql80-community-release-el7-1.noarch


// 移除  出现完毕即可

[root@localhost ~]# yum remove mysql-community-common-8.0.13-1.el7.x86_64
。。。。。
删除:
  mysql-community-common.x86_64 0:8.0.13-1.el7                                              
完毕!                                                


// 移除  出现完毕即可

[root@localhost ~]# yum remove mysql80-community-release-el7-1.noarch
。。。。。
删除:
  mysql80-community-release.noarch 0:el7-1       
完毕!                                            


// 安装之前查看mysql是否存在

[root@localhost ~]# rpm -qa | grep -i mysql  


// 查找与之相匹配的文件                            

[root@localhost ~]# find / -name mysql
find: ‘/run/user/1000/gvfs’: 权限不够
/etc/selinux/targeted/active/modules/100/mysql
/etc/selinux/targeted/tmp/modules/100/mysql
/var/lib/mysql
/var/lib/mysql/mysql
/usr/share/mysql


// 移除这三个相关的文件

[root@localhost ~]# rm -rf /var/lib/mysql
[root@localhost ~]# rm -rf /var/lib/mysql/mysql              
[root@localhost ~]# rm -rf /usr/share/mysql


// 查看是否存在mariadb  如果存在移除

[root@localhost ~]# rpm -pa | grep mariadb


// 查看时候存在相关的mysql仓储  如果存在移除

[root@localhost ~]# yum repolist all | grep mysql


// 安装mysql-server服务

[root@localhost ~]# yum install mysql-community-server
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: centos.ustc.edu.cn
 * updates: centos.ustc.edu.cn
没有可用软件包 mysql-community-server。
错误:无须任何处理


// 切换到/usr/local目录之下 

[root@localhost ~]# cd /usr/local


// 查看目录结构

[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root  6 4月  11 2018 bin
drwxr-xr-x. 2 root root  6 4月  11 2018 etc
drwxr-xr-x. 2 root root  6 4月  11 2018 games
drwxr-xr-x. 2 root root  6 4月  11 2018 include
drwxr-xr-x. 2 root root  6 4月  11 2018 lib
drwxr-xr-x. 2 root root  6 4月  11 2018 lib64
drwxr-xr-x. 2 root root  6 4月  11 2018 libexec
drwxr-xr-x. 2 root root  6 4月  11 2018 sbin
drwxr-xr-x. 5 root root 49 12月 17 18:34 share
drwxr-xr-x. 2 root root  6 4月  11 2018 src


// 创建mysql文件夹

[root@localhost local]# mkdir mysql 


// 查看目录结构,确保创建成功

[root@localhost local]# ll
总用量 0
drwxr-xr-x. 2 root root  6 4月  11 2018 bin
drwxr-xr-x. 2 root root  6 4月  11 2018 etc
drwxr-xr-x. 2 root root  6 4月  11 2018 games
drwxr-xr-x. 2 root root  6 4月  11 2018 include
drwxr-xr-x. 2 root root  6 4月  11 2018 lib
drwxr-xr-x. 2 root root  6 4月  11 2018 lib64
drwxr-xr-x. 2 root root  6 4月  11 2018 libexec
drwxr-xr-x. 2 root root  6 12月 17 19:24 mysql
drwxr-xr-x. 2 root root  6 4月  11 2018 sbin
drwxr-xr-x. 5 root root 49 12月 17 18:34 share
drwxr-xr-x. 2 root root  6 4月  11 2018 src


// 切换到创建的目录结构之下

[root@localhost local]#  cd mysql


// 查看是否创建成功

[root@localhost mysql]# ll
总用量 0


// 安装mysql8

[root@localhost mysql]# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
--2018-12-17 19:26:33--  https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Found
位置:https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm [跟随至新的 URL]
--2018-12-17 19:26:34--  https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 23.35.181.109
正在连接 repo.mysql.com (repo.mysql.com)|23.35.181.109|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:25820 (25K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el7-1.noarch.rpm”

100%[===========================================>] 25,820      --.-K/s 用时 0.1s    

2018-12-17 19:26:35 (195 KB/s) - 已保存 “mysql80-community-release-el7-1.noarch.rpm” [25820/25820])


// 查看是否安装成功

[root@localhost mysql]# ll
总用量 28
-rw-r--r--. 1 root root 25820 4月  18 2018 mysql80-community-release-el7-1.noarch.rpm


//  安装mysql80-community-release

[root@localhost mysql]# rpm -qpl mysql80-community-release-el7-1.noarch.rpm
/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
/etc/yum.repos.d/mysql-community-source.repo
/etc/yum.repos.d/mysql-community.repo
[root@localhost mysql]# rpm -ivh mysql80-community-release-el7-1.noarch.rpm
准备中...                          ################################# [100%]
正在升级/安装...
   1:mysql80-community-release-el7-1  ################################# [100%]


// 查看安装mysql安装状态

[root@localhost mysql]# yum list installed | grep mysql
mysql80-community-release.noarch        el7-1                          installed


// 显示所有启用的mysql

[root@localhost mysql]# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community      禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - So 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community      禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - So 禁用
mysql-connectors-community/x86_64  MySQL Connectors Community       启用:     74
mysql-connectors-community-source  MySQL Connectors Community - Sou 禁用
mysql-tools-community/x86_64       MySQL Tools Community            启用:     74
mysql-tools-community-source       MySQL Tools Community - Source   禁用
mysql-tools-preview/x86_64         MySQL Tools Preview              禁用
mysql-tools-preview-source         MySQL Tools Preview - Source     禁用
mysql55-community/x86_64           MySQL 5.5 Community Server       禁用
mysql55-community-source           MySQL 5.5 Community Server - Sou 禁用
!mysql56-community/x86_64          MySQL 5.6 Community Server       禁用
mysql56-community-source           MySQL 5.6 Community Server - Sou 禁用
mysql57-community/x86_64           MySQL 5.7 Community Server       禁用
mysql57-community-source           MySQL 5.7 Community Server - Sou 禁用
mysql80-community/x86_64           MySQL 8.0 Community Server       启用:     49
mysql80-community-source           MySQL 8.0 Community Server - Sou 禁用


// 显示所有启用的mysql

[root@localhost mysql]# yum repolist enabled | grep mysql
mysql-connectors-community/x86_64       MySQL Connectors Community            74
mysql-tools-community/x86_64            MySQL Tools Community                 74
mysql80-community/x86_64                MySQL 8.0 Community Server            49


// 正式安装,直至出现完毕

[root@localhost mysql]#  yum install mysql-community-server
。。。。。。。。。。。。。。。       
  验证中      : mysql-community-client-8.0.13-1.el7.x86_64     4/4 

已安装:
  mysql-community-server.x86_64 0:8.0.13-1.el7                         
作为依赖被安装:
  mysql-community-client.x86_64 0:8.0.13-1.el7  
  mysql-community-common.x86_64 0:8.0.13-1.el7  
  mysql-community-libs.x86_64 0:8.0.13-1.el7   

完毕!


// 启动mysql相关配置

[root@localhost mysql]# service mysqld restart
Redirecting to /bin/systemctl restart mysqld.service


// 查看mysql运行状态

[root@localhost mysql]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since 一 2018-12-17 19:31:45 CST; 6s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 10304 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 10385 (mysqld)
   Status: "SERVER_OPERATING"
    Tasks: 38
   CGroup: /system.slice/mysqld.service
           └─10385 /usr/sbin/mysqld

12月 17 19:31:36 localhost.localdomain systemd[1]: Starting MySQL Server...
12月 17 19:31:45 localhost.localdomain systemd[1]: Started MySQL Server.


// 获取安装mysql的临时密码

[root@localhost mysql]# grep 'temporary password' /var/log/mysqld.log
2018-12-17T11:31:39.894732Z 5 [Note] [MY-010454] [Server] A temporary password is 
generated for root@localhost: 4?OYjK


// 登陆,进行改密码

[root@localhost mysql]# mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
[root@localhost mysql]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.13

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> alter user 'root'@'localhost' identified by 'Qwe123.0!';
Query OK, 0 rows affected (0.06 sec)
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.13    |
+-----------+
1 row in set (0.00 sec)

mysql> status;
--------------
mysql  Ver 8.0.13 for Linux on x86_64 (MySQL Community Server - GPL)

Connection id:          9
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         8.0.13
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8mb4
Db     characterset:    utf8mb4
Client characterset:    utf8mb4
Conn.  characterset:    utf8mb4
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 2 min 14 sec

Threads: 2  Questions: 11  Slow queries: 0  Opens: 123  Flush tables: 2  Open tables: 99  Queries per second avg: 0.082
--------------

mysql> create database testdb;
Query OK, 1 row affected (0.12 sec)

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

mysql> use testdb;
Database changed
mysql> 

你可能感兴趣的:(Linux,学习)