centos7使用的MariaDB,替代了早期版本默认的MySQL。MariaDB是MySQL的一个分支,由开源社区维护,采用GPL授权许可,且MariaDB完全贱人MySQL。

检查centos7下现有的MariaDB安装包:
[hadoop@hadoop01 ~]$ rpm -qa| grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64

删除MariaDB安装包:
[hadoop@hadoop01 ~]$ su root
Password:
[root@hadoop01 hadoop]# rpm -e --nodeps mariadb-libs-5.5.60-1.el7_5.x86_64

下载mysql安装包:
mysql-8.0.17-1.el7.x86_64.rpm-bundle.tar
注:要对应各自centos的版本,我用的是centos7

检查是否安装其他mysql包:
rpm -qa | grep mysql

安装mysql:
rpm -ivh mysql-community-common-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.17-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.17-1.el7.x86_64.rpm

成功结果:
[root@hadoop01 hadoop]# rpm -ivh mysql-community-common-8.0.1
warning: mysql-community-common-8.0.17-1.el7.x86_64.rpm: Head
Preparing...                          #######################
Updating / installing...
   1:mysql-community-common-8.0.17-1.e#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-libs-8.0.17-
warning: mysql-community-libs-8.0.17-1.el7.x86_64.rpm: Header
Preparing...                          #######################
Updating / installing...
   1:mysql-community-libs-8.0.17-1.el7#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-client-8.0.1
warning: mysql-community-client-8.0.17-1.el7.x86_64.rpm: Head
Preparing...                          #######################
Updating / installing...
   1:mysql-community-client-8.0.17-1.e#######################
[root@hadoop01 hadoop]# rpm -ivh mysql-community-server-8.0.1
warning: mysql-community-server-8.0.17-1.el7.x86_64.rpm: Head
Preparing...                          #######################
Updating / installing...
   1:mysql-community-server-8.0.17-1.e#######################

mysql启动关闭状态:
[root@hadoop01 hadoop]# service mysqld start --启动
Redirecting to /bin/systemctl start mysqld.service
[root@hadoop01 hadoop]# service mysqld stop --关闭
Redirecting to /bin/systemctl stop mysqld.service
[root@hadoop01 hadoop]# 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: inactive (dead) since Tue 2019-09-17 01:23:32 CST; 24s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 9334 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 9247 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 9334 (code=exited, status=0/SUCCESS)
   Status: "Server shutdown complete"

Sep 17 01:17:08 hadoop01 systemd[1]: Starting MySQL Server...
Sep 17 01:17:19 hadoop01 systemd[1]: Started MySQL Server.
Sep 17 01:23:30 hadoop01 systemd[1]: Stopping MySQL Server...
Sep 17 01:23:32 hadoop01 systemd[1]: Stopped MySQL Server.

首次登陆获取自动生成的临时密码:
[root@hadoop01 hadoop]# sudo grep 'temporary password' /var/log/mysqld.log
2019-09-16T17:17:17.183833Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: ?jeVxKndj40d
[root@hadoop01 hadoop]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.17

Copyright (c) 2000, 2019, 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账户的登陆密码才能进行数据库相关操作。
--修改密码命令:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPassword' 创建授权删除查询新用户:
mysql> create user 'User'@'localhost' identified by 'User_123456'; --创建
Query OK, 0 rows affected (0.02 sec)
mysql> grant all privileges on *.* to 'User'@'localhost'; --授权
Query OK, 0 rows affected (0.02 sec)
mysql> drop user User@localhost; --删除
Query OK, 0 rows affected (0.01 sec)
mysql> select user,host from mysql.user;--查询
+------------------+-----------+
| user | host |
+------------------+-----------+
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+-----------+
4 rows in set (0.01 sec) 我们进行如下操作:
mysql> create user 'User'@'localhost' identified by 'User_123456';
Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'localhost';
Query OK, 0 rows affected (0.01 sec) mysql> create user 'User'@'%' identified by 'User_123456';
Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'%';
Query OK, 0 rows affected (0.01 sec) mysql> create user 'User'@'master' identified by 'User_123456';
Query OK, 0 rows affected (0.01 sec) mysql> grant all privileges on *.* to 'User'@'master';
Query OK, 0 rows affected (0.02 sec) mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| User | % |
| User | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| User | master |
+------------------+-----------+
7 rows in set (0.00 sec) mysql数据库的基本操作:
mysql> create database test_db;--创建数据库
Query OK, 1 row affected (0.01 sec) mysql> show databases; --展示数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| test_db |
+--------------------+
5 rows in set (0.07 sec) mysql> use test_db; --进入数据库
Database changed
mysql> create table myclass ( --创建数据表
-> id int(4) not null primary key auto_increment,
-> name char(20) not null,
-> sex int(4) not null default '0',
-> degree double(16,2));
Query OK, 0 rows affected, 3 warnings (0.04 sec) mysql> insert into myclass values(0001,"Liu Qin Jiang",0,100.00); --插入数据
Query OK, 1 row affected (0.02 sec) mysql> select * from myclass; -查询数据
+----+---------------+-----+--------+
| id | name | sex | degree |
+----+---------------+-----+--------+
| 1 | Liu Qin Jiang | 0 | 100.00 |
+----+---------------+-----+--------+
1 row in set (0.00 sec) mysql> drop table myclass; -删除数据表
Query OK, 0 rows affected (0.03 sec) mysql> drop database test_db; --删除数据库
Query OK, 0 rows affected (0.02 sec)

【mysql】centos7下mysql的安装以及基本操作的更多相关文章

  1. centos7下使用yum安装mysql

    CentOS7的yum源中默认好像是没有mysql的.为了解决这个问题,我们要先下载mysql的repo源. 1. 下载mysql的repo源 wget http://repo.mysql.com/m ...

  2. Linux - centos7 下 MySQL(mariadb) 和 主从复制

    目录 Linux - centos7 下 MySQL(mariadb) 和 主从复制 MySQL(mariadb) 安装MySQL(mariadb) 配置数据库的中文支持 在远程用 mysql客户端去 ...

  3. Centos7 下mysql大小写敏感问题

    在Centos7 下mysql大小写敏感问题,会导致程序运行时找不到对应的表. 解决办法: 第一步:编辑/etc/my.cnf文件,在[mysqld]节下 添加 lower_case_table_na ...

  4. Centos7 下mysql 密码重置

    Centos7 下mysql 密码重置 先停止mysql服务 mysqld_safe --skip-grant-tables & mysql mysql> use mysql;mysql ...

  5. [转]Centos7下caffe的安装

    Centos7下caffe的安装 原文地址:http://blog.csdn.net/s2392735818/article/details/49796017   版权声明:本文为博主原创文章,未经博 ...

  6. centos7下搜狗输入法的安装教程

    相信用过centos自带的输入法的朋友都会感叹这也实在是太难用了吧,使用拼音打出来的词总是不能在前几个匹配到,即使是一些常用词也是如此,简直无法忍受跟个zz似的.吐槽完了,这里给出centos7下搜狗 ...

  7. centos7下使用yum安装pip

    centos7下使用yum安装pip 首先安装epel扩展源: yum -y install epel-release 更新完成之后,就可安装pip: yum -y install python-pi ...

  8. Centos7 下的SVN安装与配置

    Centos7 下的SVN安装与配置 1.关闭防火墙 临时关闭防火墙 systemctl stop firewalld 永久防火墙开机自关闭 systemctl disable firewalld 临 ...

  9. CentOS7 下源码安装 python3

    CentOS 7 下源码安装 python3   在CentOS7下,默认安装的是python2.7:为满足项目要求,安装python3 的方法如下:   1. 首先安装python3.6可能使用的依 ...

  10. CentOS7下RabbitMQ服务安装配置

    参考文档: CentOS7下RabbitMQ服务安装配置 http://www.linuxidc.com/Linux/2016-03/129557.htm 在linux下安装配置rabbitMQ详细教 ...

随机推荐

  1. 环境变量path的值大于1024的解决办法

    原文传送门:https://blog.csdn.net/jytxj111/article/details/43916421 1.打开Path,点击默认文本(WIN 10),将所有路径备份下来 2.新建 ...

  2. 《你必须知道的javascript(上)》- 2.this与对象原型

    1 关于this 1.1 为什么使用this 随着你的使用模式越来越复杂,显式传递上下文对象会让代码变得越来越混乱,使用this则不会这样.当我们介绍对象和原型时,你就会明白函数可以自动引用合适的上下 ...

  3. 【414 error】nginx GET请求过长导致414错误

    server{ ... } 在上面一段配置中添加如下两行 client_header_buffer_size 5120k; large_client_header_buffers 5120k; 并重启 ...

  4. 乐橙平台大华监控Android端实时预览播放

    一.初始化 首先我们需要到乐橙开放平台下载android对应的开发包,将sdk中提供的jar和so文件添加到项目中: 二.获取监控列表 监控列表我们是通过从自家后台服务器中获取的,这个自己根据需要调整 ...

  5. windows 安装node.js

    安装node.js 这里我们是直接下载的编译后的zip包 地址:https://nodejs.org/en/download/ 点击下载相应的zip版本 这里我把zip包最里面一层的东西,所有内容放在 ...

  6. springboot获取上下文ApplicationContext

    在springboot主程序里改成 public static void main(String[] args) { // SpringApplication.run(SpringbootAPP.cl ...

  7. (idea maven)mybatis-generator步骤

    1.新建一个maven项目,选择maven-archetype-webapp 点击next 2.项目名称,点击next 3.选择项目存放路径,然后点击finish 4.在main包下 添加包java和 ...

  8. Java开发笔记(一百四十)JavaFX的选择框

    与Swing一样,JavaFX依然提供了三种选择框,它们是复选框CheckBox.单选按钮RadioButton.下拉框ComboBox,分别说明如下: 一.复选框CheckBox复选框允许同时勾选多 ...

  9. 【C++札记】友元

    C++封装的类增加了对类中数据成员的访问限制,从而保证了安全性.如想访问类中的私有成员需要通过类中提供的公共接口来访问,这样间接的访问方式,无疑使得程序的运行效率有所降低. 友元的提出可以使得类外的函 ...

  10. 链表习题(8)-寻找单链表中数据域大小为k的结点,并与前一结点交换,如果前一结点存在的情况下

    /*寻找单链表中数据域大小为k的结点,并与前一结点交换,如果前一结点存在的情况下*/ /* 算法思想:定义两个指针,pre指向前驱结点,p指向当前结点,当p->data == k的时候,交换 p ...