Mariadb 数据库管理系统
MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可。开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜在风险,因此社区采用分支的方式来避开这个风险。 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品。在存储引擎方面,使用XtraDB(英语:XtraDB)来代替MySQL的InnoDB。 MariaDB由MySQL的创始人Michael Widenius(英语:Michael Widenius)主导开发,他早前曾以10亿美元的价格,将自己创建的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨文收购,MySQL的所有权也落入Oracle的手中。MariaDB名称来自Michael Widenius的女儿Maria的名字。
简介
MariaDB基于事务的Maria存储引擎,替换了MySQL的MyISAM存储引擎,它使用了Percona的 XtraDB,InnoDB的变体,分支的开发者希望提供访问即将到来的MySQL 5.4 InnoDB性能。这个版本还包括了 PrimeBase XT (PBXT) 和 FederatedX存储引擎。
1.Mariadb 的安装与使用
yum install mariadb-server -y
配置好yum源以后,查找并安装mariadb服务
启动mariadb服务,并设置开机自启动
vim /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
skip-networking=1 关闭数据库开启的网络接口
尝试打开数据库成功
关闭数据库开启的网络接口
重启服务,查看端口状态
systemctl start mariadb
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] ##是否要设定数据库超级用户密码
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] ##是否删除匿名用户访问权限
... 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] ##是否禁止超级用户通过远程登陆
... 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] ##刷新数据库
- 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]
... 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!
数据库安全初始化,设定root密码
尝试用root身份登录成功
数据库的基本sql语句操作
1.登陆
mysql -uroot -pwestos###-u表示指定登陆用户,-p 表示指定此用户密码
2.查询
show databases;##显示数据库
use mysql;##进入mysql库
show tables;##显示当前库中表的名称
select * from user;##查询user表中的所有内容(*可以用此表中的任何字段来代替)
desc user;##查询user表的结构(显示所有字段的名称)
select * from user where Host='127.0.0.1';##查询user表中地址为127.0.0.1的内容
3.数据库及表的建立
create database westos;
use westos;
create table linux(
username varchar(15) not null,
password varchar(15) not null,
age varchar(4)
);
insert into linux values ('user1','passwd1','age1');
insert into linux values ('lee','123','20');
创建weswestos
创建Linux数据表,加入表中信息
重命名Linux为message
在表中添加class项,查看表格信息
先删除以前的class,然后重新添加class到制定位置
4.更新数据库信息
update linux set password=password('passwd2') where username=user1;
update linux set password=password('456') where ( username='user1' or username='user2' );
##更新user1和user2的密码
alter table linux rename message;#修改名称
delete from linux where username=user1;
alter table linux add class varchar(50);加入class列
alter table linux add age varchar(5) after name;在name后面加age列
alter table linux drop age;删除age列
update linux set class='linux';把class列更改为linux
update linux set class='java' where username='lee';把lee所在的行的linux内容改为java
5.删除数据库
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表
mysql -uroot -pwestos -e "create database westos;"##建立westos库
mysql -uroot -pwestos westos < /mnt/westos.sql##把数据导入westos库
重新创建westos数据库和westos中的Linux表,为后面实验用
备份westos库中的信息到/mnt
删除原有westos库
恢复westos库及其所有信息
7.用户授权
create user lee@localhost identified by 'lee';##建立用户lee,此用户只能通过本机登陆
create user lee@'%' identified by 'lee';##建立用户lee,此用户可以通过网络登陆
grant insert,update,delete,select on westos.test to lee@localhost; ##用户授权
grant select on westos.* to lee@'%'
show grants for lee@'%'##查看用户授权
show grants for lee@localhost
revoke delete on westos.test from lee@localhost;##去除用户授权权力
drop user lee@'%'##删除用户
添加用户lee并设定密码为lee
查看lee被授权的功能
测试权限是否生效
删除用户(用root用户删除)lee,不能登陆
8.密码修改
mysqladmin -uroot -pwestos password lee##修该超级用户密码
##当超级用户密码忘记
mysqld_safe --skip-grant-tables &##开启mysql登陆接口并忽略授权表
mysql##直接不用密码可以登陆
update mysql.user set Password=password('123') where User='root';##更新超级用户密码信息
ps aux | grep mysql##过滤mysql的所有进程并结束这些进程
kill -9 mysqlpid
systemctl start mariadb##重新开启mysql
mysql -uroot -p123##登陆测试
停止服务,开启mysql登陆接口但忽略授权表
停止和mysql有关的进程,可以用密码登陆
数据库的网页管理工具
1.安装
yum install httpd php php-mysql -y
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
需要下载
phpMyAdmin-3.4.0-all-languages.tar.bz2
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html
mv phpMyAdmin-3.4.0-all-languages/ mysqladmin
cd mysqladmin
cp -p config.sample.inc.php config.inc.php
vim config.inc.php
17 $cfg['blowfish_secret'] = 'mysql';
systemctl restart httpd
测试:
访问
http://172.25.254.100/mysqladmin
安装所需软件
解压软件包,并更名
随意填入
在主机进行登陆测试,成功!