MySQL入门——在Linux下安装和卸载MySQL

摘要:本文主要学习了如何在Linux系统中安装和卸载MySQL数据库。

查看有没有安装过MySQL

使用命令查看有没有安装过:

 [root@localhost ~]# yum list installed | grep mysql
[root@localhost ~]#

从CentOS版本6开始,官方版本的yum源中用MariaDB替换了MySQL,新的Linux系统中将不会默认安装MySQL,安装MySQL一般需要去官网下载rpm包或者源码包等方式。

安装MySQL源码包

查看yum可用的软件包

因为如果没有源码包,yum的仓库里是没有MySQL的安装包的,使用命令查看yum仓库里有关MySQL的软件包:

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

找到源码包下载链接

MySQL的官网地址如下:

https://www.mysql.com

登录官网如图:

将页面滑动到下面,点击Red Hat Enterprise Linux 7对应的Download下载按钮:

在新的页面找到下方的地址链接,右键复制链接地址:

下载源码包

在Linux系统中使用wget命令下载rpm包,地址即为刚刚在MySQL官网复制的链接地址:

 [root@localhost ~]# wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
---- ::-- https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
正在解析主机 dev.mysql.com (dev.mysql.com)... 137.254.60.11
正在连接 dev.mysql.com (dev.mysql.com)|137.254.60.11|:... 已连接。
已发出 HTTP 请求,正在等待回应... Found
位置:https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm [跟随至新的 URL]
---- ::-- https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
正在解析主机 repo.mysql.com (repo.mysql.com)... 184.26.157.95
正在连接 repo.mysql.com (repo.mysql.com)|184.26.157.95|:... 已连接。
已发出 HTTP 请求,正在等待回应... OK
长度: (25K) [application/x-redhat-package-manager]
正在保存至: “mysql80-community-release-el7-.noarch.rpm.” %[=====================================================================================================>] , .9KB/s 用时 .3s -- :: (88.9 KB/s) - 已保存 “mysql80-community-release-el7-.noarch.rpm.” [/]) [root@localhost ~]#

安装源码包

使用命令安装MySQL的源码包:

 [root@localhost ~]# yum install -y mysql80-community-release-el7-.noarch.rpm
已加载插件:fastestmirror
正在检查 mysql80-community-release-el7-.noarch.rpm: mysql80-community-release-el7-.noarch
mysql80-community-release-el7-.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 mysql80-community-release.noarch..el7- 将被 安装
--> 解决依赖关系完成 依赖关系解决
...
完毕!
[root@localhost ~]#

再次查看yum仓库中的源码包

使用命令查看yum仓库中有关MySQL的软件包:

 [root@localhost ~]# 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-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - So 禁用
!mysql-connectors-community/x86_64 MySQL Connectors Community 启用:
mysql-connectors-community-source MySQL Connectors Community - Sou 禁用
!mysql-tools-community/x86_64 MySQL Tools Community 启用:
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 启用:
mysql80-community-source MySQL 8.0 Community Server - Sou 禁用
[root@localhost ~]#

可以看到,目前默认安装版本是8.0。

修改安装版本

如果要修改MySQL的安装版本,可以通过修改repo配置文件或者通过执行修改命令来实现。

1)修改文件

编辑mysql-community.repo文件,将 [mysql80-community] 下面的enable设置为0表示关闭8.0版本,然后将 [mysql56-community] 下面的enable设置为1表示开启5.6版本。

命令如下:

 [root@localhost ~]# vim /etc/yum.repos.d/mysql-community.repo

2)修改命令

关闭8.0版本:

 [root@localhost ~]# yum-config-manager --disable mysql80-community
已加载插件:fastestmirror
====================================================== repo: mysql80-community =======================================================
[mysql80-community]
...
enabled =
...
[root@localhost ~]#

开启5.6版本:

 [root@localhost ~]# yum-config-manager --enable mysql56-community
已加载插件:fastestmirror
====================================================== repo: mysql56-community =======================================================
[mysql56-community]
...
enabled =
...
[root@localhost ~]#

安装MySQL

安装

使用yum命令安装:

 [root@localhost ~]# yum install -y mysql-community-server
...
======================================================================================================================================
Package 架构 版本 源 大小
======================================================================================================================================
正在安装:
mysql-community-server x86_64 5.6.-.el7 mysql56-community M
为依赖而安装:
mysql-community-client x86_64 5.6.-.el7 mysql56-community M
mysql-community-common x86_64 5.6.-.el7 mysql56-community k
mysql-community-libs x86_64 5.6.-.el7 mysql56-community 2.0 M
net-tools x86_64 2.0-0.24.20131004git.el7 base k
...
完毕!
[root@localhost ~]#

查看安装版本

使用命令查看MySQL的安装版本:

 [root@localhost ~]# mysql -V
mysql Ver 14.14 Distrib 5.6., for Linux (x86_64) using EditLine wrapper
[root@localhost ~]#

启动服务

使用systemctl命令启动并查看MySQL的服务状态:

 [root@localhost ~]# systemctl start mysqld
[root@localhost ~]# systemctl status mysqld
● mysqld.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since 三 -- :: CST; 23s ago
Process: ExecStartPost=/usr/bin/mysql-systemd-start post (code=exited, status=/SUCCESS)
Process: ExecStartPre=/usr/bin/mysql-systemd-start pre (code=exited, status=/SUCCESS)
Main PID: (mysqld_safe)
CGroup: /system.slice/mysqld.service
├─ /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─ /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mysqld.log... 8月 :: localhost.localdomain mysql-systemd-start[]: PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
8月 :: localhost.localdomain mysql-systemd-start[]: To do so, start the server, then issue the following commands:
8月 :: localhost.localdomain mysql-systemd-start[]: /usr/bin/mysqladmin -u root password 'new-password'
8月 :: localhost.localdomain mysql-systemd-start[]: /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
8月 :: localhost.localdomain mysql-systemd-start[]: Alternatively you can run:
8月 :: localhost.localdomain mysql-systemd-start[]: /usr/bin/mysql_secure_installation
8月 :: localhost.localdomain mysql-systemd-start[]: which will also give you the option of removing the test
8月 :: localhost.localdomain mysqld_safe[]: :: mysqld_safe Logging to '/var/log/mysqld.log'.
8月 :: localhost.localdomain mysqld_safe[]: :: mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
8月 :: localhost.localdomain systemd[]: Started MySQL Community Server.
[root@localhost ~]#

连接数据库

MySQL的5.6版本安装完成后,默认root用户是没有密码的,使用命令登录:

 [root@localhost ~]# mysql -uroot
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version: 5.6. MySQL Community Server (GPL) Copyright (c) , , 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>

查看版本号

使用 select version(); 命令可以查询MySQL的版本:

 mysql> select version();
+-----------+
| version() |
+-----------+
| 5.6.45 |
+-----------+
1 row in set (0.00 sec) mysql>

简单配置

使用命令对MySQL进行简单配置:

 [root@localhost ~]# mysql_secure_installation

 NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

输入当前的密码,如果没有设置就回车:

 In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here. Enter current password for root (enter for none):
OK, successfully used password, moving on...

是否为root用户设置密码:

 Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation. Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

是否删除匿名用户:

 By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment. Remove anonymous users? [Y/n]
... Success!

是否允许root用户远程登录:

 Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n]
... Success!

是否删除test数据库:

 By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment. Remove test database and access to it? [Y/n]
- Dropping test database...
ERROR (HY000) at line : Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!

是否重新加载权限表:

 Reloading the privilege tables will ensure that all changes made so far
will take effect immediately. Reload privilege tables now? [Y/n]
... Success!

设置完成:

 All done!  If you've completed all of the above steps, your MySQL
installation should now be secure. Thanks for using MySQL! Cleaning up...
[root@localhost ~]#

卸载MySQL

查看MySQL已安装的软件包:

 [root@localhost ~]# yum list installed | grep mysql
mysql-community-client.x86_64 5.6.-.el7 @mysql56-community
mysql-community-common.x86_64 5.6.-.el7 @mysql56-community
mysql-community-libs.x86_64 5.6.-.el7 @mysql56-community
mysql-community-server.x86_64 5.6.-.el7 @mysql56-community
mysql80-community-release.noarch el7- installed
[root@localhost ~]#

使用yum命令卸载:

 [root@localhost ~]# yum remove -y mysql80-community-release.noarch mysql-community-client mysql-community-server mysql-community-common mysql-community-libs
...
======================================================================================================================================
Package 架构 版本 源 大小
======================================================================================================================================
正在删除:
mysql-community-client x86_64 5.6.-.el7 @mysql56-community M
mysql-community-common x86_64 5.6.-.el7 @mysql56-community 2.1 M
mysql-community-libs x86_64 5.6.-.el7 @mysql56-community 9.2 M
mysql-community-server x86_64 5.6.-.el7 @mysql56-community M
mysql80-community-release noarch el7- installed k
...
完毕!
[root@localhost ~]#

MySQL入门——在Linux下安装和卸载MySQL的更多相关文章

  1. MySQL入门——在Linux下安装和卸载MariaDB

    MySQL入门——在Linux下安装和卸载MariaDB 摘要:本文主要学习了如何在Linux系统中安装和卸载MariaDB数据库. 查看有没有安装过MariaDB 使用命令查看有没有安装过: [ro ...

  2. linux下安装和卸载mysql

      卸载: 1 . rpm -qa | grep -i mysql命令查看已经安装过的组件.   2. 使用yum -y remove命令卸载已经安装的MySQL组件,使用下面的命令,对于上面已经安装 ...

  3. 在linux下安装并配置mysql数据库

    在linux下安装并配置mysql数据库 工具/原料   MySql5.6 CentOS 方法/步骤   1 查找以前是否安装有mysql,使用下面命令: rpm -qa|grep -i mysql ...

  4. MySQL入门——在Windows下安装MySQL

    MySQL入门——在Windows下安装MySQL 摘要:本文主要说明了如何下Windows环境下安装MySQL. 查看电脑上是否安装了MySQL 打开cmd窗口,输入 services.msc 命令 ...

  5. 在Linux下安装和使用MySQL

    [简 介] 想使用Linux已经很长时间了,由于没有硬性任务一直也没有系统学习,近日由于工作需要必须使用Linux下的MySQL.本以为有Windows下使用SQL Server的经验,觉得在Linu ...

  6. Linux下安装以及使用MySQL数据库

    1.官网下载mysql数据库:https://dev.mysql.com/downloads/mysql/ 2.linux 下可直接下载:wget https://cdn.mysql.com//Dow ...

  7. Linu下安装与卸载MySQL数据库

    卸载MySQL数据库,具体操作如下: (1)rpm -qa | grep -i mysql // 检查是否安装了MySQL的组件 (2)卸载前先关闭MySQL服务, a. b. (3)删除MySQL各 ...

  8. linux下安装+配置+卸载jdk

    一. 解压安装jdk在shell终端下进入jdk1.7.0_55.bin文件所在目录, 执行命令 ./jdk1.7.0_55.bin 这时会出现一段协议,连继敲回车,当询问是否同意的时候,输入yes, ...

  9. 在linux中安装和卸载mysql

    [安装] 已经获取到linux版本的mysql安装包,包括mysql的server(服务端)和client(客户端)的安装包,假设安装包为: MySQL-server-5.0.22-0.i386.rp ...

随机推荐

  1. PHP 将某个http地址的远程图片下载到本地的某个目录

    代码: function getImage($url,$save_dir='',$filename='',$type=0){ if(trim($url)==''){ return array('fil ...

  2. Java编程思想——第21章 并发

    前言 对于某些问题,如果能够并行的执行程序中的多个部分,则回变得非常方便甚至必要,这些部分要么看起来是并发执行,要么是在多处理环境下同时执行.并行编辑可以使程序执行速度得到极大提高,或者为设计某些类型 ...

  3. Cypress 之 URL访问

    visit 作用: 访问一个远程URL. (建议:使用前设置 baseUrl) 语法: cy.visit(url) cy.visit(url, options) cy.visit(options) 使 ...

  4. [Spring cloud 一步步实现广告系统] 13. 索引服务编码实现

    上一节我们分析了广告索引的维护有2种,全量索引加载和增量索引维护.因为广告检索是广告系统中最为重要的环节,大家一定要认真理解我们索引设计的思路,接下来我们来编码实现索引维护功能. 我们来定义一个接口, ...

  5. OpenCV:图像的合并和切分

    导包: import numpy as np import cv2 import matplotlib.pyplot as plt def show(image): plt.imshow(image) ...

  6. 剑指offer 27:二叉搜索树与双向链表

    题目描述 输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表.要求不能创建任何新的结点,只能调整树中结点指针的指向. 解题思路 采用中序遍历遍历二叉树,利用二叉排序树的特性,顺次连接节点,形成 ...

  7. 高级语言——java

    高级语言——java 起源与发展 1991 年,James Gosling 博士发布产品 Oak,这是 Java 语言的前身. 1995 年,Oak 语言改名为 Java. 1996 年,JDK(Ja ...

  8. 中间人攻击,HTTPS也可以被碾压

    摘要: 当年12306竟然要自己安装证书... 原文:知道所有道理,真的可以为所欲为 公众号:可乐 Fundebug经授权转载,版权归原作者所有. 一.什么是MITM 中间人攻击(man-in-the ...

  9. 微信小程序根据生日获取年龄

    // 根据出生日期计算年龄周岁 传参格式为1996-06-08 // 根据出生日期计算年龄周岁 传参格式为1996-06-08 function getAge(strBirthday) { var r ...

  10. docker改变默认存储路径到数据盘(自己实践)

    一.首先将数据盘格式化分区并挂载(文章中提到的sdb(腾讯云)实践中是vdb(阿里云),文章中挂载在ssd目录下,实践中是挂载到data目录下的,后面安装docker部分以后是实践中的记录,上面数据盘 ...