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)

最新文章

  1. XE3随笔17:实例 - 模拟 Google 搜索
  2. sqlplus 初始化文件(每一次打开sqlplus不用重新设置 linesize 和 pagesize)
  3. android文件存储位置切换
  4. js中Number
  5. spring源码分析之spring-web http详解
  6. 有关collection中的一些数据结构
  7. 【无源汇上下界最大流】SGU 194 Reactor Cooling
  8. ActionBar +Tab+ViewPager +Fragment 支持侧滑动完成办税工具的页面展示
  9. ArcGIS 10.3 for Desktop新特性介绍
  10. js设置文本框只能输入数字
  11. hdu 5429(大数模板)
  12. leetcode 217 Contains Duplicate 数组中是否有重复的数字
  13. luogu 3538/bzoj 2795 Poi2008 哈希+质数结论
  14. 修改hosts文件用来观看coursera视频
  15. 为什么还原innobackupex备份后查看到的Executed_Gtid_Set与xtrabackup_binlog_info不一致
  16. python 全栈开发,Day94(Promise,箭头函数,Django REST framework,生成json数据三种方式,serializers,Postman使用,外部python脚本调用django)
  17. 安装启动kafka
  18. SpringBoot 实现前后端分离的跨域访问(CORS)
  19. 变态跳台阶(python)
  20. html 表格中添加圆

热门文章

  1. python修改内存,(修改植物大战僵尸)
  2. 上海学生事务中心&amp;新华路派出所的位置
  3. Foxmail管理多个邮箱
  4. poj2396 Budget 上下界可行流
  5. P2762 太空飞行计划问题 最大权闭合子图
  6. codeforces 877 E. Danil and a Part-time Job(线段树(dfs序))
  7. CodeForces 346C Number Transformation II
  8. maven打包插件maven-assembly-plugin
  9. centos安装流量监控软件,并指定端口号监控
  10. b146: NOIP2004 1.不高兴的津津