Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6875101
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: 系统运维

2015-04-16 09:25:20

RHCE7认证学习笔记36——MariaDB数据库配置与管理

[日期:2015-04-14] 来源:Linux社区  作者:linjohn [字体:  ]

RHCE7认证学习笔记36——MariaDB数据库配置与管理

MariaDB数据库的操作使用与MySQL基本相同。

一、配置

安装MariaDB数据库

[root@linuxidc ~]# yum install mariadb\* -y

启动mariadb服务:

[root@linuxidc ~]# systemctl start mariadb

防火墙添加mysql服务:

[root@linuxidc ~]# firewall-cmd --add-service=mysql --permanent

修改配置文件/etc//my.cnf文件,添加以下编解内容:

character-set-server=utf8

数据库文件存储位置:

datadir=/var/lib/mysql

二、管理数据库

查看数据库:

MariaDB [(none)]> show databases;

查看当前数据库:

MariaDB [(none)]> select database();

查看当前用户:

MariaDB [(none)]> select user();

查看数据库当前的所有属性信息:

MariaDB [(none)]> status

进入数据库:

MariaDB [(none)]> use school;

显示表:

1  MariaDB [school]> show tables;

创建表:

MariaDB [school]> create table teacher(id int,name varchar(10),gender varchar(5) )

查看表结构:

MariaDB [school]> desc teacher;

查询和插入表数据:

1  MariaDB [school]> select * from teacher;

MariaDB [school]> insert into teacher values('1','lisi','male');

清空表内容:

MariaDB [school]> truncate table teacher;

添加列:

MariaDB [school]> alter table teacher add department varchar(20) [first|after column];

删除列:

MariaDB [school]> alter table teacher drop department;

外和内连接:

MariaDB [school]> select * from teacher  join student using(id);

MariaDB [school]> select * from teacher inner join student where a.id=b.id;

三、配置数据库

用户管理:

MariaDB [(none)]> use mysql;

MariaDB [mysql]> desc users;

MariaDB [mysql]> select host,user,password from user;

给用户root设置密码的方法:

1、

 [root@linuxidc ~]# mysqladmin -uroot -p password ''

2、

 MariaDB [(none)]> set password=password('redhat');

3、

 MariaDB [(none)]> update mysql.user set password=password('redhat') where user='root' and host='localhost';

MariaDB [(none)]> flush privileges;

忘记root密码重新设置密码,使用以下2种方式重新修改密码:

1、修改my.cnf文件,加入以下语句:

skip-grant-tables

直接进入数据库无需密码,然后执行以下修改密码的命令:

MariaDB [(none)]> update mysql.user set password=password('redhat') where user='root' and host='localhost';

MariaDB [(none)]> flush privileges;

2、使用mysqld-safe命令修改密码

先停止mysqld服务,再修改密码:

 [root@linuxidc ~]# systemctl stop mariadb.service

[root@linuxidc ~]# mysqld_safe --skip-grant-tables

MariaDB [(none)]> update mysql.user set password=password('redhat') where user='root' and host='localhost';

MariaDB [(none)]> flush privileges;

创建普通用户并设置密码:

MariaDB [(none)]> create user ;

MariaDB [(none)]> create user ;任意主机

MariaDB [(none)]> set password for );

给用户设置权限:

查看用户的权限:

MariaDB [(none)]> show grants for redhat;

查看系统的所有权限:

MariaDB [(none)]> show privileges;

授权给用户:

MariaDB [(none)]> grant create,insert,drop,update on school.* to  identified by 'redhat';

回收权限:

MariaDB [(none)]> revoke drop,update on school.* from redhat;

四、数据库的备份与恢复

冷备份:停机备份数据库文件;

热备份:

使用mysqldump命令备份:

[root@linuxidc ~]# mysqldump -u root -p school teacher student> /mysql_backup/teacher.sql

备份整个数据库表,后面则不需要指定任何表:             

[root@linuxidc ~]# mysqldump -u root -p school> /mysql_backup/all_tables.sql

备份整个数据库:

[root@linuxidc ~]# mysqldump -u root -p -B school> /mysql_backup/all.sql

进入库恢复表或者恢复表:     

MariaDB [school]> source /mysql_backup/teacher.sql;

[root@linuxidc ~]# mysql -u root -p'redhat' < /mysql_backup/all.sql

将表数据保存到文件,修改备份目录的属主属组信息:

[root@linuxidc ~]# setfacl -m u:mysql:rwx /mysql_backup/

MariaDB [school]> select * from teacher into outfile '/mysql_backup/teacher_data'fields terminated by ',';

根据外部文件恢复表数据:

MariaDB [school]> load data infile '/mysql_backup/teacher_data' into table teacher fields terminated by ',';

mysqldump不能做增量备份:

--------------------------------------分割线 --------------------------------------

在 /RHEL/Scientific Linux 6 下安装 LAMP (Apache with MariaDB and PHP) 

MariaDB Proxy读写分离的实现 

Linux下编译安装配置MariaDB数据库的方法 

CentOS系统使用yum安装MariaDB数据库 

安装MariaDB与MySQL并存 

 上如何将 MySQL 5.5 数据库迁移到 MariaDB 10  

[翻译]Ubuntu 14.04 (Trusty) Server 安装 MariaDB  

MariaDB 的详细介绍
MariaDB 的下载地址

本文永久更新链接地址

阅读(683) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~