Mariadb

来源:互联网 发布:淘宝卖家充值平台 编辑:程序博客网 时间:2024/05/19 11:46
   介绍:MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可MariaDB的目的是完全兼容MySQL,包括API和命令行,是MySQL的代替品。而MariaDB由MySQL的创始人Michael Widenius主导开发,MariaDB的名称来自Michael Widenius的女儿Maria的名字

1)安装

yum search mariadb               yum install mariadb-server.x86_64 -y

2)登录

systemctl start mariadb      ##开启mariadb的服务systemctl enable mariadb     ##开机启动systemctl stop firewalld     ##关闭防火墙mysql                        ##本机登录mysql -uroot -h IP           ##远程登录,IP为装有mysql的计算机的IP

这里写图片描述

mysql_secure_installation            ##设置安全访问,完成后,即可使用密码登录mysql -uroot -p

这里写图片描述

3)数据库的管理
1.查询
show database; ##显示数据库列表
这里写图片描述
use mysql; ##使用数据库
show tables; ##显示表单
这里写图片描述
desc user; ##查看表格结构
这里写图片描述
select * from user; ##查询user的数据
select * from user where HOST=’127.0.0.1’
2.创建

create database westos;    ##创建westos的数据库use westos;                ##使用westos的数据库create table linux(        ##创建表格   username varchar(50) not null,   password varchar(50) not null,   age varchar(50) );insert into linux values ('lee','123','20')  ##往表格中插入数据

这里写图片描述
3.修改

alter table linux rename to message;   ##修改表名alter table linux add class varchar(50);  ##向表中添加字段alter table linux add class varchar(50) after password; alter table linux drop class;  ##删除表中某字段update linux set class='linux';  ##修改表中字段的信息update linux set class='java' where username='lee';

4.备份

mysqldump -uroot -predhat westos > /mnt/westos.sql  ##将数westos的数据库备份到/mnt/下,命名为westos.sqldrop database westos;mysql -uroot -predhat -e "create database westos;"mysql -uroot -predhat westos < /mnt/wetsos.sql

5.删除

delete from linux where username='lee' and class='Java';drop table linux;drop database WESTOS;

6.数据库密码忘记怎么办?

systemclt stop mariadbmysqld_safe --skip-grant-tables &进入数据库更新密码use mysqlupdate user set Password=password('redhat') where User='root';ps aux | grep mysqlkill -9 数据库进程systemctl restart mariadb

这里写图片描述
7.授权
授权首先得由接受授权的对象,所以,应该先添加数据库用户

create user lee@localhost idenfified by 'lee';  ##创建用户leeshow grants for lee@localhost; ##查看lee都有哪些权限例1:给lee用户westos数据库下的所有表的select权限    grant select on westos.* to lee@localhost;例2:撤销lee用户在westos数据库下所有表的drop权限    revoke drop on westos.* from lee@localhost flush privileges;   ##重载授权表

8.mysql的图形管理工具

yum install httpd -y      ##安装客户端访问的浏览器systemctl start httpdsystemctl enable httpd
phpMyAdmin的安装:下载 --> 解压到Apache的默认发布目录  --> 重命名为:mysqladmincd /var/www/html/mysqladmincp config.sample.inc.php config.inc.phpless Documentation.txtvim config.inc.php
systemctl stop firewalldsystemctl disable firewalld
yum install php -y       ##安装phpyum install php-mysql.x86_64
测试:     firefox      http://172.25.254.108/mysqladmin      ##使用图形化界面管理Mysql数据库,sql语句会自动生成

这里写图片描述

这里写图片描述

原创粉丝点击