linux学习之旅(二十)& mariadb数据库
来源:互联网 发布:账户表数据库设计 编辑:程序博客网 时间:2024/06/16 09:22
mariadb概述
起源:
MySQL之父Widenius先生离开了Sun之后,觉得依靠Sun/Oracle来发展MySQL,实在很不靠谱,于是决定另开分支,这个分支的名字叫做MariaDB。Maria是他女儿的名字
-
兼容性:
MariaDB跟MySQL在绝大多数方面是兼容的,对于开发者来说,几乎感觉不到任何不同。目前MariaDB是发展最快的MySQL分支版本,新版本发布速度已经超过了Oracle官方的MySQL版本。
-
Mysql出现的问题:
在Oracle控制下的MySQL开发,有两个主要问题:
1. MySQL核心开发团队是封闭的,完全没有Oracle之外的成员参加。很多高手即使有心做贡献,也没办法做到。
2. MySQL新版本的发布速度在Oracle收购Sun之后大为减缓。Widenius有一个ppt,用数据比较了收购之前和之后新版本的发布速度。有很多bugfix和新的feature,都没有及时加入到发布版本之中。
以上这两个问题,导致了各个大公司,都开发了自己定制的MySQL版本,包括Yahoo!/Facebook/Google/阿里巴巴+淘宝网等等。
-
MariaDB的特点:
与 MySQL 相比较,MariaDB 更强的地方在于:
Maria 存储引擎 , PBXT 存储引擎 , XtraDB 存储引擎 , FederatedX 存储引擎 , 更快的复制查询处理 , 线程池 ,更少的警告和bug , 运行速度更快 , 更多的 Extensions (More index parts, new startup options etc) , 更好的功能测试 , 数据表消除 , 慢查询日志的扩展统计, 支持对 Unicode 的排序
-
MySQL是开源社区的资产,主要由开源社区在维护 ,任何个人/组织都无权据为己有。为了依靠广大MySQL社区的力量来更快速的发展MySQL,另外开分支是必须的。
MariaDB默认的存储引擎是Maria,不是MyISAM。Maria可以支持事务,但是默认情况下没有打开事务支持,因为事务支持对性能会有影响。可以通过以下语句,转换为支持事务的Maria引擎。ALTER TABLE
tablename
ENGINE=MARIA TRANSACTIONAL=1;
mariadb数据库的建立与操作
1、安装mariadb
yum install mariadb-server.x86_64 -y //安装mariadb数据库systemctl start mariadb //开启数据库
2、数据库安全设置
netstat -antple | grep mysql ##查看端口是否打开
vim /etc/my.cnf //关闭端口 skip-networking=1 //在注释行后添加
systemctl restart mariadb添加之后,查看端口,已经关闭了
mysql_secure_installation ##设置登陆密码 mysql -uroot -p ##登陆数据库
3、数据库的使用
1> 查询
查看有的库 : show datebases;
//进入mysql这个库 : use mysql;
显示数据库里的所有表格 : show tables;
//查看 user表的结构 : desc user;
查看一个表格的所有内容, * : 所有字段select * from user;查看一个表格中有关键词的部分select * from user where Host='127.0.0.1';
2> 创建
create database westos; #创建叫westos的数据库 use westos; #进入这个数据库MariaDB [westos]> show tables;Empty set (0.00 sec)MariaDB [westos]> create table linux ( ##创建linux表 -> username varchar(50) not null, -> password varchar(50) not null, -> age varchar(4) );Query OK, 0 rows affected (0.33 sec)
//在userinf表格中插入数据MariaDB [westos]> insert into linux values ('yuan','123','18');MariaDB [westos]> insert into linux values ('lee','123','20');MariaDB [westos]> insert into linux values ('li','123','20');//查看这个表格的内容MariaDB [westos]> select * from linux;
3> 修改
修改表格linux的名称为message : alter table linux rename message;
添加属性:alter table linux add class varchar(50); 删除表格中的class列:alter table linux drop class;
在password之后添加属性: alter table linux add class varchar(50) after password;
update linux set class='linux'; ##改class这一列的所有属性update linux set class='java' where username='lee'; ##改一行中的一个属性
4> 删除
删除username=lee且class=java的行delete from linux where username='lee' and class='java';
#删除表格linuxdrop table linux; #删除数据库westosdrop database westos;
5> 备份与恢复
mysqldump -uroot -predhat westos > /mnt/westos.sql #将westos数据库备份到/mnt下[root@dnst ~]# mysql -uroot -predhat -e "drop database westos" #删除westos数据库[root@dnst ~]# mysql -uroot -predhat -e "create database westos" #建立一个westos数据库[root@dnst ~]# mysql -uroot -predhat westos < /mnt/westos.sql #将原westos数据库中的数据导入到新的数据库中*注: 也可以在文件中上方的读取westos数据库信息之前直接填写 :CREATE DATABASE westos;USE westos;然后直接[root@dnst ~]# mysql -uroot -predhat < /mnt/westos.sql 就可以直接导入"但是注意,这里面的文件都是数据库的重要信息,一旦更改出错是有可能造成数据库混乱的的,所以尽量不要去碰这个文件"
6> 忘记密码
//停止mariadbsystemctl stop mariadb//启动安全模式,且跳过认证表,不启动授权表, & :进程打入后台mysqld_safe --skip-grant-tables &此时直接输入命令 mysql //不需要密码直接进入数据库
//进入mysql use mysqlselect * from user;//发现 其中User,Password都是首字母大写,密码是加密的。密码部分 :" *84BB5DF4823DA319BBF86C99624479A198E6EEE9 "//无密码加密修改密码: 修改里面的userMariaDB [mysql]> update user set Password= 'westos' where User='root';| root | westos | //这是显示的结果,修改的密码没有加密//加密密码修改:MariaDB [mysql]> update user set Password=password('westos') where User='root'; | root | *28C1E2BE21B45562A34B6CC34A19CFAFC2F88F96 | //显示的结果,密码有加密//查看有关mysql的进程 ps ax | grep mysql kill -9 mysql的进程 systemctl start mariadb //重启数据库,生效
7> 用户和访问权限
创建一个yuan用户,只能从本机登陆,登陆密码为westoscreate user yuan@localhost identified by 'westos';创建一个yuan用户,可以从任何地方登陆,登陆密码为westoscreate user yuan@'%' identified by 'westos'; ## '%' : 任何地方登陆
对yuan用户授权:grant insert,update,delete,select,drop on westos.* to yuan@localhost;## westos.* 表示对数据库westos授权,若是 *.*表示对所有数据库授权
重新加载授权表 : flush privileges;## 授权表是默认自动刷新。但是如果,改完没作用,手动刷新查看yuan用户的授权表:show grants for yuan@localhost;撤销用户的授权 :revoke insert,update,delete,drop on westos.* from yuan@localhost;删除用户:drop user yuan@localhost;
数据库的网页图形管理
mysql的图形管理工具 : phpmyadmin
安装
yum install httpd -ysystemctl start httpd //开启httpdsystemctl enable httpdsystemctl stop firewalld //关闭火墙systemctl disable firewalld//因为软件是用php写的,所以系统需要php的解释器 ,所以要安装php相应软件yum install php php-mysql -ysystemctl restart httpdsystemctl stop firewalld还需要软件包: phpMyAdmin-3.4.0-all-languages.zip //下载数据库网页软件压缩包
配置
tar jxf phpMyAdmin-3.4.0-all-languages.tar.gz2 -C /var/www/html //解压压缩包并存放到/var/www/html mv phpMyAdmin-3.4.0-all-languages mysqladmin //重命名(为了方便查看)cd mysqladmin //进入这个目录
查看README文件 ,
less README
发现要查看当前文件中的 Documentation.txt
less Documentation.txt
发现需要修改文件,还要添加信息,不过文件中改填写的内容包括格式都已经给出了
下面就是照着文件中的去改 : cp -p config.sample.inc.php config.inc.php ##修改配置文件
vim config.inc.php$cfg['blowfish_secret'] = 'ba17c1ec07d65003'; ##里面的字符可以随便写
systemctl restart httpd 重启httpd服务生效
测试:
http://172.25.254.109/mysqladmin
因为是最简单的安装,所以显示缺少扩展,这里不用管它,直接进入就可以
//这样,就可以通过网络管理你的数据库
- linux学习之旅(二十)& mariadb数据库
- linux之数据库mariadb
- linux学习之mariadb
- Linux学习笔记 --Mariadb数据库
- linux学习之二十---消息队列
- Linux学习之二十、循环
- linux系统之mariadb 数据库管理系统
- 运维学习之mariadb数据库管理
- Linux学习篇第三章之~mariadb
- linux的mariadb数据库
- Linux-mariadb数据库管理
- Linux中的mariadb----数据库
- Linux学习之二十(特殊权限SUID详解)
- Linux学习笔记--MariaDB数据库配置与管理
- 学习笔记之MariaDB - 关系型数据库基础
- Python 操作Mariadb数据库 +Linux
- Linux学习篇第三章之~postfix & mariadb
- MariaDb数据库管理系统学习(二)使用HeidiSQL数据库图形化界面管理工具
- 【思维导图训练2】--发散思维的秘诀
- 013讲爬虫网站图片
- maven工程的创建(四)--运行测试
- 【Quartz】——与spring整合
- POJ 3630:Phone List(字典树入门)
- linux学习之旅(二十)& mariadb数据库
- CodeForces
- (UVA
- easyUI选项卡—右键关闭tabs
- Python:字符串中指定位置插入一个字符
- java基础第九天 static
- Django初探(1)
- 快速幂运算(入门完整版)
- extjs之editor