广告
返回顶部
首页 > 资讯 > 数据库 >数据库之mariadb整体概述
  • 378
分享到

数据库之mariadb整体概述

2024-04-02 19:04:59 378人浏览 安东尼
摘要

一、数据库的安装方式及其安装步骤 1、安装方式 rpm包安装,yum安装,二进制包安装,编译安装   2、安装步骤 (本文是使用二进制包安装)1)下载mariadb相

一、数据库的安装方式及其安装步骤 

1、安装方式 

rpm包安装,yum安装,二进制包安装,编译安装   

2、安装步骤 (本文是使用二进制包安装)

1)下载mariadb相应版本的数据库,解压 

tar xf mariadb-5.5.48-linux-86_64.tar.gz -C /usr/local/ 

2)创建软链接及其创建用户和存放数据目录和授权其目录文件 

cd /usr/local 

ln -sv mariasb-5.5.48 Mysql 

chown -R root.mysql mysql

groupadd -r mysql 

useradd -r -g mysql mysql 

mkdir /mydata/data -pv  

chown -R mysql.mysql /mydata/data 

3)给数据库提供配置文件及其启动脚本 

cp /usr/local/mysql/support-files/my-large.cnf /etc/my.cnf  

cp /usr/local/mysql/support-files/my.server /etc/init.d/mysqld 

chkconfig --add /etc/init.d/mysqld  

chkconfig mysqld on  

4)给/etc/my.cnf加上如下项

datadir=/mydata/data

skip-name-resolve=ON 

innodb-file-per-table=ON  

5)初始化数据库及其启动数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/mydata/data

service mysqld start   

6)执行mysql_secure_installation命令设置密码及其删除匿名用户等操作

[root@Centos6 ~]# 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.
You already have a root password set, so you can safely answer 'n'.
Change the root password? [Y/n] n
 ... skipping.
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] n
 ... skipping.
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] n
 ... skipping.
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!


二、MariaDB基础 

1、配置文件查找次序

/etc/my.cnf/-->/etc/mysql/my.cnf-->~/.my.cnf  

2、mariadb的命令行交互式客服端工具 

mysql[options] [database] 

常用选项: 

 -u:username,用户名,默认为root 

 -h:host远程主机或地址,默认为localhost  

 -p:password,用户的密码 

 -D:database_name,设置指定连接库

 -e:直接在命令行运行mysql数据库中的命令

实例:mysql -uroot -hlocalhost -p mysql -utestuser -h20.1.%.% -p  mysql -uroot -p -e 'show databases';


图示: 



数据库之mariadb整体概述


3、mariadb数据库命令行客服端命令

常用帮助参数如下注释

[root@centos7 ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 19
Server version: 5.5.44-MariaDB MariaDB Server
Copyright (c) 2000, 2015, oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> \? #获取帮助也可使用help命令
General information about MariaDB can be found at
Http://mariadb.org
List of all MySQL commands:
Note that all text commands must be first on line and end with ';'
?         (\?) Synonym for `help'. #获取帮助信息
clear     (\c) Clear the current input statement. #清除当前行的输入
connect   (\r) Reconnect to the server. Optional arguments are db and host. #重连数据库
delimiter (\d) Set statement delimiter.
edit      (\e) Edit command with $EDITOR.
ego       (\G) Send command to mysql server, display result vertically. #竖立显示信息
exit      (\q) Exit mysql. Same as quit. #退出当前的数据库
go        (\g) Send command to mysql server. #发送命令到数据库
help      (\h) Display this help.
nopager   (\n) Disable pager, print to stdout.
notee     (\t) Don't write into outfile.
pager     (\P) Set PAGER [to_pager]. Print the query results via PAGER.
print     (\p) Print current command.
prompt    (\R) Change your mysql prompt.
quit      (\q) Quit mysql.
rehash    (\#) Rebuild completion hash.
source    (\.) Execute an SQL script file. Takes a file name as an argument.
status    (\s) Get status information from the server.
system    (\!) Execute a system shell command.
tee       (\T) Set outfile [to_outfile]. Append everything into given outfile.
use       (\u) Use another database. Takes database name as argument.
charset   (\C) Switch to another charset. Might be needed for processing binlog with multi-byte charsets.
warnings  (\W) Show warnings after every statement.
nowarning (\w) Don't show warnings after every statement.
For server side help, type 'help contents'
MariaDB [(none)]>


4、数据库常用数据类型 

1)字符型 

char,varchar,binary,varbinary,txt,blob...

2)数值型

int,float,double,tinyint... 

3)枚举型 

set,enum  

4)时间日期型

date,time,datetime,timestamp,year  

5)数据类型修饰符

unsigned,not null,default  


三、服务端命令

1、数据定义语言(DDL),主要用于管理数据库组件,例如索引,视图,用户,存储过程,主要命令有:create,alter,drop。

对库的操作:

创建:create 

create {database|schema} [if not exists] db_name 

修改:alter 

alter {database|schema} [db_name] 

删除:drop 

drop {database|schema} [if exists] {db_name}


查看支持的字符集:show character set 

查看支持的所有排序的规则:show collation;


图示: 



数据库之mariadb整体概述


对表的操作: 

创建表: 

create [temporary] table [if not exists] tbl_name 


修改表:

alter [online|offline] [ignore] table tbl_name  

字段:   

    添加:add [column] col_name column_definition  

    删除:drop [column] col_name 

    修改:change [column] old_col_name new_col_name column_definition 

              modify [column] col_name column_definition 

键:

    添加:ADD [CONSTRaiNT [symbol]] PRIMARY KEY 

      add {primary key unique key foreign}(col1,col2...)

    删除:

主键:drop primary key   

外键:drop foreign key fk_name

索引:

    添加:add {index|key} {index_name} 

    删除:drop {index|key} index_name  


主要实例如下:

create database testdb; 
use testdb;
create table if not exists students(id int unsigned NOT NULL primary key, name char(20) NOT NULL, age tinyint unsigned, gender enum('f','m'));
alter table students add class varchar(20) not null after age;  
alter table students change gender sex enum('f','m');
alter table students modify class char(30) after sex; 
alter table students drop primary key ;
alter table students add primary key(id,name);
alter table students add index class (class);
alter table students drop index class;


图示:


创建库、表及其查看表结构

数据库之mariadb整体概述

添加和修改字段名字及其类型

数据库之mariadb整体概述

修改主键及其添加主键

数据库之mariadb整体概述

查看建表信息及其表的状态信息

数据库之mariadb整体概述


2、数据操纵语言(DML),主要用于管理表中的数据,实现数据的增删改查。

插入数据:insert into 

    insert into tbl_name [cols....] values (val1,val2,...)

实例:insert into students (id,name) value (1,'alren');

          insert into students values (2,'alren',29,'m','one');

查询数据: select 

    select [col1,col2,...] from tbl_name where clause;  

实例:select * from students where id=1; 

          select name,age from students where age>11 and age<20; 

          select name,age from students where age between 11 and 20; 

          select name,age from students where name rlike 'en$'; 

          select age,sex from students where age is not; 

          select age,sex from students where age is not null; 

          select id,name from students order by id desc; 

          select id,name,age from students order by id asc;  

 更新数据:update 

    update [low_priority] [ignore] table_reference   

          update students set age=age+10 where name like '%lren'; 

删除数据:delete from  

    delete from tbl_name where clause; 

    delete from students; #删除表中的所有数据,很危险,谨慎操纵。  

    delete from students order by age desc limit 20;    


图示:


修改表为自增长

数据库之mariadb整体概述

插入数据两种方式

数据库之mariadb整体概述

查询表中数据

数据库之mariadb整体概述

更新数据

数据库之mariadb整体概述

删除数据

数据库之mariadb整体概述


四、创建用户及其授权管理 

1、创建用户账号 

create user 'username'@'host' [indentified by 'password'] 

实例:create user 'testuser'@'10.1.10.%.%' identified by 'pass';   

2、删除用户账号 

DROP USER user [, user] ...

drop user 'username'@'host' 


图示:


删除和授权用户

数据库之mariadb整体概述

测试是否授权成功

数据库之mariadb整体概述

远程登录测试成功

数据库之mariadb整体概述


3、授权管理 

grant privileges_type on [object_type] db_name.tabl_name to 'username'@'host' identified by 'password'

privileges_type:all,create,alter,drop,delete,update,insert,select  

库表的对应有如下关系:db_name.tbl_name

    *.*:所有库的中的所有表 

    db_name.*:指定库的所有表 

    db_name.tbl_name:指定库的指定表 

    db_name.routine_name:指定库上的存储函数或过程


图示:


创建test用户为其授权测试

数据库之mariadb整体概述授予test用户所有的权限

数据库之mariadb整体概述

回收用户权限 

数据库之mariadb整体概述

查看当前用户及其指定用户授权信息

数据库之mariadb整体概述

授权一用户只给查询和插入权限,则除此权限外其他权限均无    

数据库之mariadb整体概述










本文出自小耳朵原创,每天进步一点点。








您可能感兴趣的文档:

--结束END--

本文标题: 数据库之mariadb整体概述

本文链接: https://www.lsjlt.com/news/36135.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • 数据库之mariadb整体概述
    一、数据库的安装方式及其安装步骤 1、安装方式 rpm包安装,yum安装,二进制包安装,编译安装   2、安装步骤 (本文是使用二进制包安装)1)下载mariadb相...
    99+
    2022-10-18
  • 数据库概述
    原文:https://www.cnblogs.com/rainbow-ran/p/14488897.html...
    99+
    2020-02-15
    数据库概述 数据库入门 数据库基础教程
  • 数据库知识复习之数据库系统概述
    数据库是数据管理的最新技术,是计算机科学的重要分支。从联机事务处理(On-Line Transaction Processing,OLTP)到联机肥西处理(On-Line Analysis Processi...
    99+
    2022-10-18
  • 数据库软件概述
    1. 关系型数据库关系型数据库,是指采用了关系模型来组织数据的数据库。关系模型是在1970年由IBM的研究员E.F.Codd博士首先提出的,在之后的几十年中,关系模型的概念得到了充分的发展并逐渐成为主流数据...
    99+
    2022-10-18
  • 数据库备份概述
    数据库备份概述概述:将数据库中存在的现有数据,进行存放成为副本数据,可解决数据容灾;           提高系统的高可用性和灾难恢复性,数据崩溃时,以最小代价重新恢复数据;数据丢失的原因:程序错误、人为错...
    99+
    2022-10-18
  • SQL Server数据库概述
        SQL Server是一个数据库管理系统,主要是通过Windows服务来运行的。本篇主要介绍如何对数据库进行基本操作与管理启动或停止数据库服务    在完成数...
    99+
    2022-10-18
  • 数据库系统概述
    什么是数据库数据库(Database DB)指按照数据结构来组织,存储和管理数据的仓库,是存储在一起的相关数据的集合,什么是数据库管理系统数据库操作系统(Database Management Syste...
    99+
    2022-10-18
  • python数据库操作--数据库使用概述
    目录1. 数据库基础知识2. 访问数据库基本原理1.应用系统2.数据库驱动程序 3.数据库系统3. ODBC与ADO1.** ODBC**2.ADO4. 关系型数据库总结1. 数据库基础知识 数据库(DB...
    99+
    2022-06-02
    python 数据库使用
  • Oracle 数据块体系基础知识概述
    <div style="font-family:微软雅黑;font-size:14px;line-height:21px;white-space:normal;widows:auto;bac...
    99+
    2022-10-18
  • 数据库原理及应用概述
    数据库原理及应用概述 数据库原理及应用1、数据库系统概述1.1 基本概念1.2 数据模型1.3 数据库系统的结构 2、实体 -- 联系模型2.1 基本概念2.2 实体-联系图2.3 弱实体...
    99+
    2023-09-22
    数据库 mysql sqlserver 需求分析 实体-联系模型
  • 关于数据库系统的概述
    目录一、数据库的发展 人工管理阶段二、数据库系统的组成和结构三、数据库系统的体系结构四、数据模型4.1 概念模型4.2 层次模型4.3 关系模型五、练习题一、数据库的发展 人工管理阶...
    99+
    2022-11-12
  • 数据分析处理库Pandas——概述
    导入Pandas库 创建DataFrame结构 读取.csv文件 titanic_train.csv文件:https://files.cnblogs.com/files/gloria-zhang/titanic_train.rar...
    99+
    2023-01-31
    数据 Pandas
  • Oracle专题1之Oracle概述、Oracle数据库的体系结构以及常用命令
    1、Oracle概述-  Oracle Database,简称为Oracle。是美国ORACLE(甲骨文)公司的一款对象关系型的数据库管理系统(ORDBMS)。目前在数据库市场上占有主要份额。- ...
    99+
    2022-10-18
  • 【基础部分】之数据库 mariadb
    1.数据库的安装yum install mariadb.x86_64 mariadb-server.x86_64 -y关掉防火墙关闭网络端口(禁止外人访问)netstat -antlpe | grep my...
    99+
    2022-10-18
  • 数据库 | 数据库概述、关系型数据库、非关系型数据库
    目录: 1.数据库:1.1 数据库的含义1.2 数据库的特点 2.数据表3.数据库管理系统4.数据库系统5.关系型数据库 和 非关系型数据库:5.1 关系型数据库5.2 关系型数据库“优...
    99+
    2023-09-05
    数据库 oracle mysql 关系型数据库 非关系型数据库
  • 阿里云数据库的软件概述
    本文将详细介绍阿里云数据库提供的各种软件,包括关系型数据库、NoSQL数据库、分布式数据库等,帮助您了解和选择适合您业务需求的数据库软件。 阿里云数据库是阿里云提供的各种数据库服务的总称,包括关系型数据库、NoSQL数据库、分布式数据库等。...
    99+
    2023-10-29
    阿里 数据库 软件
  • openGauss数据库共享存储特性概述
    目录版本介绍继承功能:新增功能:主备共享存储特性简介客户价值特性描述特性约束openGauss 3.1.1是openGauss 5.0.0 release版本的Preview版本,希望广大社区伙伴和开发者基于此版本进行场...
    99+
    2023-02-18
    openGauss数据库共享存储 openGauss共享存储 openGauss数据库存储
  • Java数据结构之哈夫曼树概述及实现
    目录一、与哈夫曼树相关的概念二、什么是哈夫曼树三、哈夫曼树的构造方法四、哈夫曼树的代码实现一、与哈夫曼树相关的概念 概念 ...
    99+
    2022-11-12
  • Cassandra基本介绍(1) - 关系型数据库(RDBMS)概述
        作为一名应用开发者,数据库应用已经非常广泛了。你可能使用过关系型数据,比如MySQL、PostgreSQL,也可能使用过文档存储,比如MongoDB,或者ke...
    99+
    2022-10-18
  • 关系型数据库和非关系型数据库概述与优缺点对比
    目录一、关系型数据库1、概念2、关系型数据库的特点3、关系型数据库的瓶颈4、关系型数据遵循ACID原则1、A(Atomicity)原子性2、C(Consistency)一致性3、I(...
    99+
    2022-11-13
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作