您的位置:首页 > 数据库 > MariaDB

linux的mariadb数据库

2017-08-14 22:48 369 查看
一.数据库mariadb简介

MariaDB 是一个采用 Maria 存储引擎的MySQL分支版本,是由原来 MySQL 的作者Michael Widenius创办的公司所开发的免费开源的数据库服务器。[3] 

MariaDB相关书籍

这个项目的很多代码都改编于 MySQL 6.0,例如 “pool of threads”功能提供解决多数据连接问题。MariaDB 5.1.41 RC可以到这里下载,32位和64位已编译Linux版本,还包括源代码包。MariaDB基于GPL 2.0发布。

二.安装与启动服务,检查端口状态









三.安装后使用前的准备

1.关闭数据库开启的网络接口





vim /etc/my.cnf





skip-networking=1     关闭数据库开启的网络接口

2.数据库安全初始化

 mysql_secure_installation





提问解释:

Enter current password for root (enter for none):          数据库原始密码(默认没有直接回车)

Set root password? [Y/n]      是否要设定数据库超级用户密码

New password:              输入要设定的超级用户密码

Re-enter new password:          重复输入

Remove anonymous users? [Y/n]      是否删除匿名用户访问权限

Disallow root login remotely? [Y/n]          是否禁止超级用户通过远程登陆

Remove test database and access to it? [Y/n]     刷新数据库

全部点回车即可

四.数据库的基本sql语句操作

1.登陆


mysql -uroot -pwestos       -u表示指定登陆用户,-p 表示指定此用户密码





2.查询(查询语言大小写字母都可以使用,企业中为了规范需要使用大写)

show databases;         显示数据库





use mysql;           进入mysql库





show tables;           显示当前库中表的名称





desc user;         查询user表的结构(显示所有字段的名称)





select * from user;        查询user表中
d53e
的所有内容(*可以用此表中的任何字段来代替)





加上查询条件





3.数据库及表的建立

create database westos;    建立westos库,创建linux表





insert into linux values ('user1','passwd1'); 添加linux表中的信息







4.数据库的修改

alter table linux rename message;    
修改数据库表名





alter table linux add class;          在表中添加class列





在表中password后添加class列





update linux set class='linux';    更新表中的数据(全部列)





更新表中名字为lee一栏的class为jave (有条件的更新,不是整列)





5.数据库的删除

alter table linux drop class;       删除linux表中的class列





delete  from linux where username='user1';     删除user1的数据从linux表中

drop table linux;                                                删除linux表

drop database westos;                                     删除westos库





五.数据库的备份

mysqldump -u root -pwestos --all-database                          备份所有表中的左右数据

mysqldump -u root -pwestos --all-database --no-data         备份所有表,但不备份数据

mysqldump -u root -pwestos westos                                      备份westos库

mysqldump -u root -pwestos westos  > /mnt/westos.sql      备份westos库并把数据保存到westos.sql中

mysqldump -uroot -pwestos westos linux > /mnt/linux.sql   备份westos库中的linux表

mysqldump -uroot -pwestos westos test > /mnt/test.sql       备份westos库中的test表

1.备份westos库并把数据保存westos.sql中





2.删除westos库





3.恢复westos库

mysql -uroot -pwestos -e "create database westos;"     建立westos库

mysql -uroot -pwestos westos < /mnt/westos.sql           把数据导入westos库





4.进入数据库,查看westos库正常





六.密码修改

1.关闭数据库服务,开启mysql登陆接口并忽略授权表   mysqld_safe --skip-grant-tables &           





2.mysql    直接不用密码可以登陆

update mysql.user set Password=password('westos') where User='root';    更新超级用户密码信息(加密)





查看更新加密后的密码

3.ps aux | grep mysql        过滤mysql的所有进程

kill -9 mysqlpid                     结束这些进程

systemctl start mariadb       重新开启mysql

mysql -uroot -pwestos         登陆测试









七.用户授权

1.create user lee@localhost identified by 'westos'; 建立用户lee,密码westos,此用户只能通过本机登陆

   create user lee@'%' identified by 'westos';            建立用户lee,密码westos,此用户可以通过网络登陆

2.grant insert,update,delete,select on westos.test to lee@localhost;  用户授权

    grant select on westos.* to lee@'%'





3.show grants for lee@'%'                     查看用户授权

show grants for lee@localhost    





用lee用户登陆后可以查看、删除









4.revoke delete on westos.* from lee@localhost;           去除用户授权权力

去除lee用户的delete权力后无法删除表中数据









5.drop user lee@localhost           删除lee用户

   drop user lee@'%'                      删除用户





八.数据库的网页管理工具

1.安装服务和准备phpMyAdmin包

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld 

phpMyAdmin-3.4.0-all-languages.tar.bz2

2.配置数据库的网页管理工具

解压phpMyAdmin包,将解压后的目录重命名为mysqladmin





查看phpMyAdmin配置文件Documentation,找到软件码





复制phpMyAdmin中的配置模版文件,编辑模版文件,将软件码添加到配置文件中





vim config.inc.php





安装   yum install  php php-mysql -y





3.测试:访问http://172.25.254.128/mysqladmin



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: