数据库

来源:owlcity123 发布时间:2018-11-03 16:41:16 阅读量:1185

MARIADB

1)安装

yum install mariadb-server -y

systemctl start mariad






2)安全初始化

默认情况下,数据库的网络接口是打开的,为了安全需要关闭此接口

vim /etc/my.conf

  skip-networking=1

systemctl restart mariadb






3)数据库起始状态设定信息是不安全的(不需密码即可登陆数据库),需要作以下设定:

 mysqld_secure_installation

 mysql -uroot -p

 Enter password  






数据库的管理

1)建立


use westos;     进入库


show tables; 查看库中的表


show databases;列出库






create table linux ;建立表


desc linux;           查看表结构


select * from linux;  查询所有字段在linux表中


select username,password  from linux;查询指定字段在linux表中


insert into linux values(‘lee’,‘123’); 插入数据在linux表中;






2)更改


alter tables linux  add class varchar(20);  添加class字段


alter table linux drop class;    删除class字段


alter table linux add age varchar(20) after password;  在password字段后添加age字段


alter table linux rename redhat;  修改linux表的名称为redhat


update  linux set password=password('lee') where usename='lee'; 更改用户名为lee的密码为加密的lee










3)删除


delete  from redhat where username='bob';  从redhat表中删除用户名为bob的数据


drop table redhat;   删除表


drop database westos;  删除数据库






4)用户授权


数据库的root用户添加指定用户,并给其相应权力(insert,update,select,delete)


   create user lee@‘172.25.254.166’ identified by 'westos'  创建用户lee可在172.25.254.166主机登陆数据库,密码为westos


   create user lee@localhost identified by 'westos'  创建用户lee只能在本地登陆数据库,密码为westos


   grant insert,update,delete,select on westos.* to lee@localhost;   给用户insert,update,delete,select权力


   create select,insert,delete on westos.*  to lee@localhost identified by "westos"   相当于上两条命令


   flush priviliges  重载授权表


   show grants for lee@localhost;  查看用户授权


   revoke delete,update,insert on westos.* from lee@localhost   撤销用户权限


   drop user lee@localhost;   删除用户


1.添加用户lee,密码为westos






2.root用户给用户lee赋予select权力,并查看是否能够select






3.lee当前不具有插入数据的权力,让root用户授权其可以insert,并测试








4.撤销用户的insert权限




5.删除lee用户






数据库的备份


mysqldump -uroot  -plee westos > /mnt/westos.sql      备份数据


mysql -uroot -plee -e "drop database westos;"            删除数据库,看是否能够恢复




方法一:






方法二:




修改root用户密码




当超级用户密码忘记时:


systemctl stop mariadb.server    暂停服务


mysql_safe --skip-grant-tables &   进入无密码的状态


mysql  


  update mysql.user set Password=password('redhat') where User='root' ;  重新设置root用户的密码为redhat


kill -9  masql所有进程      


systemctl start mariadb    重启服务






例子:natasha 用户可以从 172.25.254.166 上登录数据库,对 redhat 库拥有查询权限,密码为 natasha_passwd


服务器端(172.25.254.86)






客户端(172.25.254.166)


在172.25.254.166主机能够远程登陆86的数据库,并且只有select权力,没有删除权力





--------------------- 

作者:owlcity123 

来源:CSDN 

原文:https://blog.csdn.net/owlcity123/article/details/81586635 

版权声明:本文为博主原创文章,转载请附上博文链接!


标签: 数据库
分享:
评论:
你还没有登录,请先