RHEL7之后操作系统带的数据库都是mariadb,跟mysql一样用

1.安装客户端和服务端

[root@localhost ~]# yum install mariadb mariadb-server -y

2.启动数据库服务,这个很重要

[root@localhost ~]# systemctl start mariadb

3.对数据库进行初始化操作

[root@localhost ~]# mysql_secure_installation 

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

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y         #重设root密码
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] y     #删除匿名用户
 ... Success!

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] y      #禁止root远程登录
 ... Success!

By default, MariaDB 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] y     #删除test数据库
 - Dropping test database...
 ... Success!
 - 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] y         #刷新表,重读刚刚的配置
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

4.登陆数据库,-uroot代表以root身份登录,不用加空格,-p验证密码

[root@localhost ~]# mysql -uroot -p
Enter password:    #这里输入密码
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

5. 查看有哪些数据库

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

6.重设密码

MariaDB [(none)]> set password = password('2');
Query OK, 0 rows affected (0.00 sec)

7.新增本地用户并设置密码

MariaDB [(none)]> create user lee@localhost identified by '3';
Query OK, 0 rows affected (0.00 sec)

8.在mysql数据库中查询lee的主机名、用户名、密码

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]> select host,user,password from user where user="lee";
+-----------+------+-------------------------------------------+
| host      | user | password                                  |
+-----------+------+-------------------------------------------+
| localhost | lee  | *C4E74DDDC9CC9E2FDCDB7F63B127FB638831262E |
+-----------+------+-------------------------------------------+
1 row in set (0.00 sec)

9.对lee授权,grant授权

MariaDB [(none)]> grant select,update,delete,insert on mysql.user to lee@localhost;
Query OK, 0 rows affected (0.00 sec)

9.1取消授权,grant变成revoke,to变成from

MariaDB [mysql]> revoke select,update,delete,insert on mysql.user from lee@localhost;
Query OK, 0 rows affected (0.00 sec)

10.查询刚刚的授权情况

MariaDB [(none)]> show grants for lee@localhost;
+------------------------------------------------------------------------------------------------------------+
| Grants for lee@localhost                                                                                   |
+------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'lee'@'localhost' IDENTIFIED BY PASSWORD '*C4E74DDDC9CC9E2FDCDB7F63B127FB638831262E' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.`user` TO 'lee'@'localhost'                                |
+------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

11.登陆lee账户,查询可以操作的数据库和表单

[root@localhost ~]# mysql -ulee -p3

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)

MariaDB [(none)]> show tables from mysql;
+-----------------+
| Tables_in_mysql |
+-----------------+
| user            |
+-----------------+
1 row in set (0.00 sec)

12.创建数据库

MariaDB [(none)]> create database LEE;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| LEE                |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

13.在新建的数据库中新建表单,并查看

MariaDB [(none)]> use LEE
Database changed
MariaDB [LEE]> create table worker (name char(15),age  int,sex char(5));
Query OK, 0 rows affected (0.00 sec)

MariaDB [LEE]> describe worker;
+-------+----------+------+-----+---------+-------+
| Field | Type     | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name  | char(15) | YES  |     | NULL    |       |
| age   | int(11)  | YES  |     | NULL    |       |
| sex   | char(5)  | YES  |     | NULL    |       |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)

13.1查看数据库中所有的表单

MariaDB [lee]> show tables;
+---------------+
| Tables_in_lee |
+---------------+
| worker        |
+---------------+
1 row in set (0.00 sec)

14.向表单中插入数据,并查看

MariaDB [LEE]> insert into worker(name,age,sex) values ('lee','18','man');
Query OK, 1 row affected, 1 warning (0.00 sec)

MariaDB [LEE]> select * from worker;
+------+------+------+
| name | age  | sex  |
+------+------+------+
| lee  |   18 | man  |
+------+------+------+
1 row in set (0.00 sec)

15.根据对应的值查找,where

MariaDB [LEE]> select * from worker;   #首先加一些数据
+--------+------+-------+
| name   | age  | sex   |
+--------+------+-------+
| lee    |   18 | man   |
| join   |   19 | man   |
| kylin  |   17 | woman |
| aobama |   40 | man   |
+--------+------+-------+
4 rows in set (0.00 sec)

MariaDB [LEE]> select * from worker where sex='man';  #查找man的数据
+--------+------+------+
| name   | age  | sex  |
+--------+------+------+
| lee    |   18 | man  |
| join   |   19 | man  |
| aobama |   40 | man  |
+--------+------+------+
3 rows in set (0.00 sec)

MariaDB [LEE]> select * from worker where sex!='man';  #查找不是man的数据
+-------+------+-------+
| name  | age  | sex   |
+-------+------+-------+
| kylin |   17 | woman |
+-------+------+-------+
1 row in set (0.00 sec)

16.数据库的备份mysqldump与恢复

[root@localhost ~]# mysqldump -uroot -p2 lee > /root/lee.dump
[root@localhost ~]# ls -l /root/lee.dump
-rw-r--r--. 1 root root 1941 7月   1 21:34 /root/lee.dump
[root@localhost ~]# mysql -uroot -p2
MariaDB [(none)]> drop database lee;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> create database lee;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> exit
Bye
[root@localhost ~]# mysql -uroot -p2 lee < /root/lee.dump
[root@localhost ~]# mysql -uroot -p2
MariaDB [(none)]> use lee
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [lee]> select * from worker;
+--------+------+-------+
| name   | age  | sex   |
+--------+------+-------+
| lee    |   18 | man   |
| join   |   19 | man   |
| kylin  |   17 | woman |
| aobama |   40 | man   |
+--------+------+-------+
4 rows in set (0.00 sec)

MariaDB简单操作的更多相关文章

  1. mysql、MariaDB的简单操作

    mysql的简单操作 一.查看数据库 SHOW DATABASES; 例如: MariaDB [(none)]> show databases; +--------------------+ | ...

  2. MySQL基本简单操作01

    MySQL基本简单操作 学会了安装Docker,那么就将它利用起来.(/滑稽脸) 之前想学习Mysql(Windows下配置真麻烦),学会了Docker就方便了,直接使用Docker创建一个Mysql ...

  3. MySQL基本概念以及简单操作

    一.MySQL   MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MyS ...

  4. x01.MagicCube: 简单操作

    看最强大脑,发现魔方还是比较好玩的,便买了一个,对照七步还原法,居然也能成功还原. 为什么不写一个魔方程序呢?在网上找了找,略作修改,进行简单操作,还是不错的,其操作代码如下: protected o ...

  5. js简单操作Cookie

    贴一段js简单操作Cookie的代码: //获取指定名称的cookie的值 function getCookie(objName) { var arrStr = document.cookie.spl ...

  6. GitHub学习心得之 简单操作

    作者:枫雪庭 出处:http://www.cnblogs.com/FengXueTing-px/ 欢迎转载 前言 本文对Github的基本操作进行了总结, 主要基于以下文章: http://gitre ...

  7. Linq对XML的简单操作

    前两章介绍了关于Linq创建.解析SOAP格式的XML,在实际运用中,可能会对xml进行一些其它的操作,比如基础的增删该查,而操作对象首先需要获取对象,针对于DOM操作来说,Linq确实方便了不少,如 ...

  8. Linux 中 Vi 编辑器的简单操作

    Linux 中 Vi 编辑器的简单操作 Vi 编辑器一共有3种模式:命名模式(默认),尾行模式,编辑模式.3种模式彼此需要切换. 一.进入 Vi 编辑器的的命令 vi  filename //打开或新 ...

  9. python(pymysql)之mysql简单操作

    一.mysql简单介绍 说到数据库,我们大多想到的是关系型数据库,比如mysql.oracle.sqlserver等等,这些数据库软件在windows上安装都非常的方便,在Linux上如果要安装数据库 ...

随机推荐

  1. 一位996、CRUD开发者的一天

    记一笔流水账 今天我打算记一笔流水账,主要记录我的一天中干的事情,并思考效率低下的原因,同时分析一些可用的解决方案. 清早·开始做计划 早上六点四十,被梦想唤醒,然后看一会书,吃早餐,送娃上学. 九点 ...

  2. P3469 [POI2008]BLO-Blockade 割点 tarjan

    题意 给定一个无向图,问删掉点i,图中相连的有序对数.(pair<x, y> , x != y);求每个点对应的答案 思路 首先我们可以发现,如果这个点不是割点,那么答案就是n-1,如果是 ...

  3. CF - 1111D Destroy the Colony DP

    题目传送门 题意: 这个题目真的是最近遇到的最难读. 有一个长度n的字符串,每一位字符都代表的是该种种类的敌人. 现在如果一个序列合法的话,就是同一种种类的敌人都在字符串的左半边或者右半边. 现在有q ...

  4. 染色 Wannafly挑战赛20 A 思维

    链接:https://www.nowcoder.com/acm/contest/133/A来源:牛客网 现在有一棵被Samsara-Karma染了k种颜色的树,每种颜色有着不同的价值 Applese觉 ...

  5. codeforces 764 C. Timofey and a tree(dfs+思维)

    题目链接:http://codeforces.com/contest/764/problem/C 题意:给出一个树,然后各个节点有对应的颜色,问是否存在以一个点为根节点子树的颜色都一样. 这里的子树颜 ...

  6. poj 2352 & Ural 1028 数星星 题解

    一道水题,由于x坐标递增y坐标也递增于是前缀和统计即可,用树状数组实现. #include<bits/stdc++.h> using namespace std; const int ma ...

  7. sed一些常用命令

    [转] http://blog.chinaunix.net/uid-20754793-id-177657.html 下面是我学习sed时参照参考书总结的一些常用sed命令,基本上每条语句都进行了调试1 ...

  8. java1.8新特性(一)接口的默认方法

    一 简介 我们通常所说的接口的作用是用于定义一套标准.约束.规范等,接口中的方法只声明方法的签名,不提供相应的方法体,方法体由对应的实现类去实现. 在JDK1.8中打破了这样的认识,接口中的方法可以有 ...

  9. RobotFramework自动化测试框架-MongoDBLibrary库的使用

    笔者接着 RobotFramework自动化测试框架-DatabaseLibrary库的使用(对数据库的操作) 继续分享robotframework 对数据库中的MongoDB的详细操作. Mongo ...

  10. 数论 Day 12

    数论是个好东西 今天讲的是组合计数 组合计数 组合数学主要是研究一组离散对象满足一定条件的安排的存在性.构造及计数问题.计数理论是狭义组合数学中最基本的一个研究方向,主要研究的是满足一定条件的排列组合 ...