欢迎投稿

今日深度:

Mariadb数据库的部署及管理,mariadb数据库部署

Mariadb数据库的部署及管理,mariadb数据库部署


前言:在这里先简单的介绍一下mariadb,其实本质上mariadb就是mysql,只不过甲骨文公司将其卖给红帽公司了,红帽公司就叫其为mairadb。不管mariadb还是mysql都是数据库。MariaDB数据库管理系统是MySQL的一个分支。
(一)数据库的安装
1 安装数据库

2 开启数据库

3 测试:

mysql    ##进入数据库

4 进入数据库:

(二)数据库的初始化
1 )安全初始化:
默认情况下,数据库的网络接口时打开的,为了安全起见,需要关闭此接口,改配置文件:

关闭网络接口:

重启数据库:
2)数据库的起始状态设定信息是不安全的,需要做以下设定:

root@apacheserver ~]# 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: 
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 ##是否删除测试库
 - 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!

(三)数据库的管理
1)修改超级用户名密码为lee:

2)当超级用户忘记密码时:
首先停止数据库:

跳过安全授权表:

进入数据库,此时不需要用户及密码:

更新密码,退出:

查找出所有数据库进程,并强行停止:

在查看数据库进程,发现没有了:

此时开启数据库,并用更新后的密码来登陆,更新成功:

(四)数据库sql语句基本操作

1.登陆
mysql -uroot -predhat ##以root登陆数据库,密码为redhat
2.查询
show databases;  ##显示数据库
show tables   ##显示表的信息
use mysql     ##进入mysql库(命令后面不带封号)
select * from user;  ##查询user表中的所有信息(*代表全部)
desc user;   ##查询user中的结构(显示所有字段的名称)

3 数据库的管理
1)建立库:

查看:

进入库,查看表:

2)新建表:

查看表:

3)插入数据到linux表中:


4)更改:
更改表中的内容,新增字段:


删除字段:

在某个字段后添加一个字段;

将表格名字改为“redhat“:

5)删除字段:

6)删除表:

7)用户授权:

1.创建用户
create user lee@localhost identified by ‘lee’; ##创建本地用户(ps:lee是通过密码认证)
create user lee@’%’ identified by ‘lee’; ##创建网络用户
2.用户授权
grant insertupdate,delete,select on westos.test to lee@localhost 
##对本地用户进行授权(westos库的test表,westos.* westos库中的所有表)
**grant insert on westos.test to lee@’%’ ##对网络用户进行授权;
3.显示授权
show grants for lee@’%’ ##显示网络用户的授权
show grants for lee@localhost ##显示普通用户的授权
4.删除授权
revoke delete on westos.test from lee@local

实验如下:

(4)数据库的备份:

1.备份文件的分类
mysqldump -uroot -pwestos  –all-database ##备份所有表中的文件
mysqldump -uroot -pwestos  –all-database –no-data ##备份所有表,但不备份数据
mysqldump -uroot -pwestos westos ##备份westos库
mysqldump -uroot -pwestos westos > /mnt/linux.sql##备份westos库,并将数据存到/mnt目录下

1)备份westos库,并将数据存到/mnt目录下

2)我们删除数据库“westos“,以便察看备份效果:

3)登陆发现westos库不在了:

4)我们现在要恢复数据库westos,其实备份文件里有westos库里的表,但是没有westos库,所以我们要先生成一个westos库,这样才可以还原,这里有两种方式:
方式一:
用命令写入的方式
还原:

进入数据库中查看:

查看表中的内容:

还原成功!接下来试试方式二,写在配置文件中:

[root@apacheserver mnt]# vim westos.sql 

将备份数据导入westosw数据库:

查看,westos库存在:

(5)安装phpmyadmin 数据库图形管理
phpmyadmin:可以用图形创建数据库表

yum install php php-mysql httpd mysql mysql-server  ###安装需要的服务
tar jxf phpmyadmin-*.tar.bz2 -C /var/www/html ##得到php包解压到默认目录
mv phpmyadmin phpadmin ##给包的目录换个名字
cp config.sample.inc.php config.inc.php   ##拷贝vei配置文件

改配置文件:

vim config.inc.php
add 
$cfg['blowfish_secret'] = 'ba17clec07d65003';

测试:
重启httpd,访问http://172.25.254.79/mysqladmin

这个软件很好用,将数据库可视化,可以新建表:


在此软件上的操作与命令是同步化的。

www.htsjk.Com true http://www.htsjk.com/mariadb/28594.html NewsArticle Mariadb数据库的部署及管理,mariadb数据库部署 前言:在这里先简单的介绍一下mariadb,其实本质上mariadb就是mysql,只不过甲骨文公司将其卖给红帽公司了,红帽公司就叫其为mairadb。不管...
相关文章
    暂无相关文章
评论暂时关闭