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庫
6.資料庫的備份
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 [email protected] identified by 'lee';##建立使用者lee,此使用者隻能通過本機登陸
create user [email protected]'%' identified by 'lee';##建立使用者lee,此使用者可以通過網絡登陸
grant insert,update,delete,select on westos.test to [email protected]; ##使用者授權
grant select on westos.* to [email protected]'%'
show grants for [email protected]'%'##檢視使用者授權
show grants for [email protected]
revoke delete on westos.test from [email protected];##去除使用者授權權力
drop user [email protected]'%'##删除使用者
添加使用者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
安裝所需軟體
解壓軟體包,并更名
随意填入
在主機進行登陸測試,成功!