MariaDB数据库管理系统
一、安装mariaDB
1、更换国内yum源
[root@template] mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
[root@template]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
2、安装mariadb
[root@template yum.repos.d]# yum install mariadb mariadb-server -y
3、启动mariadb服务程序并添加到开机启动项中
[root@template yum.repos.d]# systemctl start mariadb [root@template yum.repos.d]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
4、为了保证数据库的安全性,一定要进行初始化工作
第1步:设定root用户密码。
第2步:删除匿名帐号。
第3步:禁止root用户从远程登录。
第4步:删除test数据库并取消对其的访问权限。
第5步:刷新授权表,让初始化后的设定立即生效。
5、初始化数据库服务
[root@template ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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
New password: 输入要为root用户设置的数据库密码。
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!
设置防火墙对数据库服务的允许策略:
[root@linuxprobe ~]# firewall-cmd --permanent --add-service=mysql
success
[root@linuxprobe ~]# firewall-cmd --reload
success
使用root用户登录到数据库中:
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)
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]> show tables;
+---------------------------+
| Tables_in_mysql |
+---------------------------+
| columns_priv |
| db |
| event |
| func |
| general_log |
| help_category |
| help_keyword |
| help_relation |
| help_topic |
| host |
| ndb_binlog_index |
| plugin |
| proc |
| procs_priv |
| proxies_priv |
| servers |
| slow_log |
| tables_priv |
| time_zone |
| time_zone_leap_second |
| time_zone_name |
| time_zone_transition |
| time_zone_transition_type |
| user |
+---------------------------+
24 rows in set (0.00 sec)
MariaDB [mysql]> select host,user from user;
+-----------+------+
| host | user |
+-----------+------+
| 127.0.0.1 | root |
| ::1 | root |
| localhost | root |
+-----------+------+
3 rows in set (0.00 sec)
MariaDB [mysql]> drop user 'root'@'::1';
Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> select host,user from user;
+-----------+--------+
| host | user |
+-----------+--------+
| 127.0.0.1 | root |
| localhost | root |
+-----------+--------+
3 rows in set (0.00 sec)
6、修改当前用户在数据库中的密码(示例中的密码为nulige)
MariaDB [(none)]> set password = password('nulige');
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
二、创建用户并授权
数据库GRANT命令的授权操作常用方案:
| 命令 | 作用 |
| GRANT 权限 ON 数据库.表单名称 TO 用户名@主机名 | 对某个特定数据库中的特定表单给予授权。 |
| GRANT 权限 ON 数据库.* TO 用户名@主机名 | 对某个特定数据库中的所有表单给予授权。 |
| GRANT 权限 ON *.* TO 用户名@主机名 | 对所有数据库及所有表单给予授权。 |
| GRANT 权限1,权限2 ON 数据库.* TO 用户名@主机名 | 对某个数据库中的所有表单给予多个授权。 |
| GRANT ALL PRIVILEGES ON *.* TO 用户名@主机名 | 对所有数据库及所有表单给予全部授权,(谨慎操作)。 |
1、创建一个新的数据库用户:
创建数据库用户的命令:CREATE USER 用户名@主机名 IDENTIFIED BY '密码';
MariaDB [mysql]> create user nulige@localhost IDENTIFIED BY 'oldboy123'; Query OK, 0 rows affected (0.00 sec)
#给用户授权
MariaDB [(none)]> GRANT SELECT,UPDATE,DELETE,INSERT on mysql.user to nulige@localhost;
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> show grants for nulige@localhost;
+---------------------------------------------------------------------------------------------------------------+
| Grants for nulige@localhost |
+---------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'nulige'@'localhost' IDENTIFIED BY PASSWORD '*FE28814B4A8B3309DAC6ED7D3237ADED6DA1E515' |
| GRANT SELECT, INSERT, UPDATE, DELETE ON `mysql`.`user` TO 'nulige'@'localhost' |
+---------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
三、创建数据库与表单
常用的数据库表单管理命令有:
| 用法 | 作用 |
| CREATE database 数据库名称。 | 创建新的数据库。 |
| DESCRIBE 表单名称; | 描述表单。 |
| UPDATE 表单名称 SET attribute=新值 WHERE attribute > 原始值; | 更新表单中的数据。 |
| USE 数据库名称; | 指定使用的数据库。 |
| SHOW databases; | 显示当前已有的数据库。 |
| SHOW tables; | 显示当前数据库中的表单。 |
| SELECT * FROM 表单名称; | 从表单中选中某个记录值。 |
| DELETE FROM 表单名 WHERE attribute=值; | 从表单中删除某个记录值。 |
#创建数据库
MariaDB [(none)]> create database crm character set=utf8;
Query OK, 1 row affected (0.00 sec) #查看数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crm |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec) #进入crm
MariaDB [(none)]> use crm
Database changed #创建表,表名book
MariaDB [crm]> create table book (name char(20),price int,pages int);
Query OK, 0 rows affected (0.01 sec) MariaDB [crm]> desc book;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name | char(20) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pages | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+ #插入数据
MariaDB [crm]> INSERT INTO book(name,price,pages) VALUES('python','60',518);
Query OK, 1 row affected (0.00 sec) MariaDB [crm]> INSERT INTO book(name,price,pages) VALUES('linux','48',618);
Query OK, 1 row affected (0.00 sec) MariaDB [crm]> INSERT INTO book(name,price,pages) VALUES('go','78',818);
Query OK, 1 row affected (0.00 sec) #更新数据
MariaDB [crm]> update book set price=55;
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2 Changed: 2 Warnings: 0 #查看表中内容
MariaDB [crm]> select * from book;
+--------+-------+-------+
| name | price | pages |
+--------+-------+-------+
| python | 60 | 518 |
| linux | 48 | 618 |
| go | 78 | 818 |
+--------+-------+-------+
3 rows in set (0.00 sec) #清空book表中内容
MariaDB [crm]> delete from book;
Query OK, 2 rows affected (0.00 sec) #查看删除结果
MariaDB [crm]> select * from book;
Empty set (0.00 sec) #删除数据库
MariaDB [(none)]> drop database crm;
Query OK, 0 rows affected (0.00 sec)
where命令用于在数据库匹配查询的条件,可用的条件有:
| 参数 | 作用 |
| = | 相等。 |
| <>或!= | 不相等。 |
| > | 大于。 |
| < | 小于。 |
| >= | 大于或等于。 |
| <= | 小于或等于。 |
| BETWEEN | 在某个范围内。 |
| LIKE | 搜索一个例子。 |
| IN | 在列中搜索多个值。 |
查看价格大于75元的书籍:
MariaDB [crm]> select * from book where price>75;
+------+-------+-------+
| name | price | pages |
+------+-------+-------+
| go | 78 | 818 |
+------+-------+-------+
1 row in set (0.00 sec) 搜索价格不等于60元的书籍:
MariaDB [crm]> select * from book where price!=60;
+-------+-------+-------+
| name | price | pages |
+-------+-------+-------+
| linux | 48 | 618 |
| go | 78 | 818 |
+-------+-------+-------+
2 rows in set (0.01 sec)
四、数据库的备份与恢复
mysqldump命令用于备份数据库数据,格式为:“mysqldump [参数] [数据库名称]”。
| 参数 | 作用 |
| -u | 数据库的用户名称。 |
| -p | 密码提示符。 |
| --no-data | 指备份数据库的描述结构,而不要数据。 |
| --lock-all-tables |
备份完成后将不再允许修改数据。 |
1、备份前,先查看数据库名
#查看数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| crm |
| mysql |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)
#进入crm库
MariaDB [(none)]> use crm
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 [crm]> show tables;
+---------------+
| Tables_in_crm |
+---------------+
| book |
+---------------+
1 row in set (0.01 sec)
#查看表中数据
MariaDB [crm]> select * from book;
+--------+-------+-------+
| name | price | pages |
+--------+-------+-------+
| python | 60 | 518 |
| linux | 48 | 618 |
| go | 78 | 818 |
+--------+-------+-------+
3 rows in set (0.00 sec)
2、备份数据库
格式为:“mysqldump [参数] [数据库名称]” ,后面接保存地址
[root@template yum.repos.d]# mysqldump -u root -p crm > /root/crm.dump
Enter password: [root@template yum.repos.d]# cd /root/
[root@template ~]# ll
-rw-r--r--. 1 root root 1900 Apr 16 02:48 crm.dump
导入备份的数据
#导入备份的数据
[root@template ~]# mysql -u root -p crm < /root/crm.dump
Enter password: #登录数据库
[root@template ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 25
Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. #进入crm库
MariaDB [(none)]> use crm
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 [crm]> show tables;
+---------------+
| Tables_in_crm |
+---------------+
| book |
+---------------+
1 row in set (0.00 sec) #查看表结构
MariaDB [crm]> desc book;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| name | char(20) | YES | | NULL | |
| price | int(11) | YES | | NULL | |
| pages | int(11) | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec) #查看表中数据
MariaDB [crm]> select * from book;
+--------+-------+-------+
| name | price | pages |
+--------+-------+-------+
| python | 60 | 518 |
| linux | 48 | 618 |
| go | 78 | 818 |
+--------+-------+-------+
3 rows in set (0.00 sec)
MariaDB数据库管理系统的更多相关文章
- MariaDb数据库管理系统的学习(一)安装示意图
MariaDB数据库管理系统是MySQL的一个分支.主要由开源社区在维护,採用GPL授权许可.开发这个分支的原因之中的一个是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区採用分 ...
- 《Linux就该这么学》培训笔记_ch18_使用MariaDB数据库管理系统
<Linux就该这么学>培训笔记_ch18_使用MariaDB数据库管理系统 文章最后会post上书本的笔记照片. 文章主要内容: 初始化MariaDB服务 管理用户以及授权 创建数据库与 ...
- 第18章 使用MariaDB数据库管理系统
章节概述: MYSQL数据库管理系统被Oracle公司收购后从开源换向到了封闭,导致包括红帽在内的许多Linux发行版选择了MariaDB. 本章节将教会您使用mariaDB数据库管理工具来管理数据库 ...
- Linux基础学习-MariaDB数据库管理系统
数据库管理系统 数据库是指按照某些特定结构来存储数据资料的数据仓库,数据库管理系统是一种能够对数据库中存放的数据进行建立.修改.删除.查找.维护等操作的软件程序. 初始化MariaDB服务 [root ...
- MariaDb数据库管理系统学习(二)使用HeidiSQL数据库图形化界面管理工具
HeidiSQL 是一款用于简单化的 MySQL server和数据库管理的图形化界面.该软件同意你浏览你的数据库,管理表,浏览和编辑记录,管理用户权限等等.此外,你能够从文本文件导入数据,执行 SQ ...
- MariaDB 数据库
1. MariaDB 介绍 MariaDB数据库管理系统是 MySQL 的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成 ...
- Linux上mariadb数据库(博客初学者使用测试)
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.MariaDB由MySQL的创始人麦克尔·维德纽斯主导开发,他早前曾以10亿美元的价格,将自己创建的公司M ...
- Windows10下MariaDB数据库的安装与卸载
MariaDB数据库管理系统是MySQL的一个分支,100%兼容Mysql,开源免费,在Windows系统和Linux系统中都能运行,很受到欢迎.自从mysql被Oracle收购后,MariaDB就成 ...
- CentOS7下MariaDB数据库安装及配置
前言 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品.在存 ...
随机推荐
- 用 C# 代码如何实现让你的电脑关机,重启,注销,锁定,休眠,睡眠
简介 本文讲述了用 C# 代码如何实现让你的电脑关机,重启,注销,锁定,休眠,睡眠. 如何实现 首先,使用 using 语句添加我们需要的命名空间: using System.Diagnostics; ...
- [转]在树莓派上搭建LAMP服务
之前介绍过树莓派上LNMP环境的搭建方法,本文将详细介绍如何在树莓派上配置LAMP服务. 为LAMP,是最流行的服务器配置之一,LAMP的含义是: Linux - 操作系统 Apache - 网络服务 ...
- Symfony2之创建一个简单的web应用 Symfony2——创建bundle
bundle就像插件或者一个功能齐全的应用,我们在应用层上开发的应用的所有代码,包括:PHP文件.配置文件.图片.css文件.js文件等都会包含在bunde系统中. 可以通过两种方法 ...
- Linux core dump file详解
Linux core dump file详解 http://www.cnblogs.com/langqi250/archive/2013/03/05/2944931.html
- 利用git把本地项目传到github+将github中已有项目从本地上传更新
利用git把本地项目传到github中 1.打开git bash命令行,进入到要上传的项目中,比如Spring项目,在此目录下执行git init 的命令,会发下在当前目录中多了一个.git的文件夹( ...
- Tomcat下载安装及常见问题解决办法
一.Tomcat的下载: 下载地址:http://tomcat.apache.org/ 下载Tomcat6.0(在左侧的Download下,考虑到稳定性现在企业大部分还在用Tomcat6.0) (1) ...
- 架设Hmailserver+webmail邮件服务器
架设Hmailserver+webmail邮件服务器 在安裝Hmailserver前先安裝Apache.php.mysql,如果你想懶點直接到http://www.phpnow.org下載phpn ...
- centos6.5 安装vlc播放器【超简单】
# cd /etc/yum.repos.d/ # wget http://pkgrepo.linuxtech.net/el6/release/linuxtech.repo //我试了3次才下载下来 # ...
- 神器mimikatz使用命令方法总结
神器mimikatz使用命令方法总结 文章地址:http://www.isharepc.com/300.html mimikatz是一款功能强大的轻量级调试神器,通过它你可以提升进程权限注入进程读取进 ...
- (寒假GYM开黑)2018 German Collegiate Programming Contest (GCPC 18)
layout: post title: 2018 German Collegiate Programming Contest (GCPC 18) author: "luowentaoaa&q ...