1.yum intall mariadb-server -y ##安装mariadb服务
systemctl start mariadb ##开启服务
<a href="https://s3.51cto.com/wyfs02/M00/95/C6/wKioL1kZiX_CdXM3AAAWvJ5H8Wk052.png" target="_blank"></a>
<a href="https://s3.51cto.com/wyfs02/M02/95/C6/wKioL1kZiX_QOZY9AAAeDqhmtN8834.png" target="_blank"></a>
vim /etc/my.cnf ##修改配置文件
*
*symbolic-link=0 ##跳过符号链接
systemctl restart mariadb #重启服务
mysql_secure_installtion ##mysql加密
<a href="https://s4.51cto.com/wyfs02/M02/95/C6/wKioL1kZjE2w92U_AAAm3zswX3c462.png" target="_blank"></a>
**Enter current password for root (enter for none): ##数据库原始密码,直接回车
<a href="https://s4.51cto.com/wyfs02/M01/95/C6/wKioL1kZjF_jyiICAAAbgMI1cmo578.png" target="_blank"></a>
**Change the root password? [Y/n] y ##是否设定数据库root密码
New password: ##输入密码
Re-enter new password: ##重复密码
<a href="https://s2.51cto.com/wyfs02/M00/95/C6/wKiom1kZjQywgt2hAAAqDgXzHsY269.png" target="_blank"></a>
**Remove anonymous users? [Y/n] y ##是否删除匿名用户访问权限
<a href="https://s3.51cto.com/wyfs02/M01/95/C6/wKiom1kZjXLyKSVgAAASymSqnfU217.png" target="_blank"></a>
**Disallow root login remotely? [Y/n] y ##是否禁止超级用户远程登录
<a href="https://s2.51cto.com/wyfs02/M02/95/C6/wKioL1kZjq3RMuhFAAAWNR7MfDc676.png" target="_blank"></a>
**Remove test database and access to it? [Y/n] y ##是否删除测试数据
<a href="https://s2.51cto.com/wyfs02/M01/95/C6/wKiom1kZjrjTNmmFAAAzCLxhzZ8028.png" target="_blank"></a>
**Reload privilege tables now? [Y/n] y ##重新加载服务
<a href="https://s4.51cto.com/wyfs02/M00/95/C6/wKiom1kZjsDh1BSjAAAVnBnmdWE449.png" target="_blank"></a>
2.数据库的基本sql语句操作
(1)登录
mysql -uroot -p ##-u代表用户 -p密码
<a href="https://s1.51cto.com/wyfs02/M02/95/C6/wKioL1kZjzXCFucJAACQAYIRmw0555.png" target="_blank"></a>
(2)查询
show databases; ##显示数据库
<a href="https://s5.51cto.com/wyfs02/M02/95/C6/wKiom1kZkCLxtkacAAA8YbVKNH8633.png" target="_blank"></a>
use mysql; ##进入MySQL库
<a href="https://s4.51cto.com/wyfs02/M00/95/C6/wKioL1kZkEai9jdCAABOiPtWB0Y732.png" target="_blank"></a>
show tables; ##显示数据库里表的名称
<a href="https://s2.51cto.com/wyfs02/M02/95/C6/wKioL1kZkF_xC0RTAAA4RHx7BZk257.png" target="_blank"></a>
select * from user; ##查询user表中所有内容
<a href="https://s5.51cto.com/wyfs02/M02/95/C6/wKiom1kZkHjAo213AADGelLZfSA831.png" target="_blank"></a>
desc user; ##查询user表的结构 (显示表头)
<a href="https://s3.51cto.com/wyfs02/M00/95/C6/wKiom1kZkJLwjCojAABwsTShF1o487.png" target="_blank"></a>
(3)数据库的建立
create database westos; ##建立westos库
<a href="https://s3.51cto.com/wyfs02/M01/95/C7/wKiom1kZkaTA8zk-AABomU-79vc256.png" target="_blank"></a>
create table linux( ##建立Linux表,并且有username和password两个字段
username varchar(15) not null,
password varchar(15) not null
);
insert into linux values ('user1','123') ##给Linux表里写入内容
<a href="https://s4.51cto.com/wyfs02/M02/95/C7/wKioL1kZkfqQWDp8AABozZucYRU278.png" target="_blank"></a>
(4)数据库的更新
update linux set password=password('456') where username='user1'; ##加密更新user1密码
<a href="https://s2.51cto.com/wyfs02/M01/95/C7/wKiom1kZlKyB9-oSAABsmSzGctM095.png" target="_blank"></a>
update linux set password=password('456') where (username='user2' or username='user3'; ##更新user2和user3密码
<a href="https://s5.51cto.com/wyfs02/M01/95/C7/wKioL1kZlMnTPH1jAABrKq8aS0A477.png" target="_blank"></a>
delete from linux where where username='user1'; ##删除user1密码
<a href="https://s2.51cto.com/wyfs02/M01/95/C7/wKiom1kZlOaAPmOwAABLXM78xvs160.png" target="_blank"></a>
alter table linux add age varchar(4); ##在Linux表最后添加age列
<a href="https://s1.51cto.com/wyfs02/M00/95/C7/wKioL1kZlQOCLzZuAABcOOmTo5A124.png" target="_blank"></a>
alter table linux add year varchar(4)after age ##在age字段后添加year字段
<a href="https://s2.51cto.com/wyfs02/M02/95/C7/wKiom1kZlWaSYPlDAABmI3CT5mQ466.png" target="_blank"></a>
alter table linux drop age ; ##删除age字段
(5)删除数据库
drop table linux ##删除Linux表
<a href="https://s4.51cto.com/wyfs02/M00/95/C7/wKiom1kZllLz1R6DAABCTE4mz04883.png" target="_blank"></a>
drop database westos ##删除westos库
<a href="https://s4.51cto.com/wyfs02/M00/95/C7/wKiom1kZlm_CvWXgAAByOQ3QXgM122.png" target="_blank"></a>
(6)数据库的备份
mysqldump -u root -p123 --all -database ##备份表中所有数据
<a href="https://s3.51cto.com/wyfs02/M00/95/C7/wKioL1kZmHuivt9pAAEMQzmcvNI372.png" target="_blank"></a>
mysqldump -u root -p123 --all -database --no-data ##备份所有表,不备份数据
mysqldump -u root -p123 westos ##备份westos库
<a href="https://s3.51cto.com/wyfs02/M01/95/C7/wKioL1kZmLOiWyHKAAFJDWKVUOo731.png" target="_blank"></a>
mysqldump -u root -p123 westos > /mnt/westos.sql ##备份westos库保存到westos.sql
mysqldump -u root -p123 westos linux > /mnt/linux.sql ##备份westos库中的Linux表
<a href="https://s2.51cto.com/wyfs02/M02/95/C7/wKioL1kZmQOyLclUAAAggHe_q9M702.png" target="_blank"></a>
mysql -u root -p123 -e "create database westoss;" ##建立westos库
mysql -u root -p123 westos < /mnt/linux.sql ##导入数据到westos库
**测试
<a href="https://s3.51cto.com/wyfs02/M00/95/C7/wKiom1kZmWawaMcxAABLJ9FU5J4168.png" target="_blank"></a>
(7)用户授权
create user ws@localhost identified by 'ws'; ##创建用户ws,只能通过本机登录
<a href="https://s3.51cto.com/wyfs02/M01/95/C7/wKioL1kZmrmykAAzAACMYSGpPME333.png" target="_blank"></a>
create user ws@'%' identified by 'ws'; ##创建用户ws,只能通过网络登录
grant insert,update,delete,select on westos.linux to ws@localhost ##用户授权
revoke delete on westos.linux from ws@localhost ##删除用户授权
<a href="https://s2.51cto.com/wyfs02/M01/95/C8/wKioL1kZmxaCfg5SAACRy4a8yic011.png" target="_blank"></a>
drop user ws@'%' ##删除用户
<a href="https://s3.51cto.com/wyfs02/M00/95/C8/wKiom1kZm0mDZ3LEAABPSGzgkHQ967.png" target="_blank"></a>
(8)修改密码
mysqladmin -uroot -p123 password 456
<a href="https://s1.51cto.com/wyfs02/M02/95/C8/wKioL1kZm6ShawCxAACmZp80USc335.png" target="_blank"></a>
mysqld_safe --skip-grant-table & ##开启MySQL登录接口忽略授权表
<a href="https://s1.51cto.com/wyfs02/M01/95/C8/wKioL1kZnVjAlcJMAABvKcb7rJc434.png" target="_blank"></a>
mysql ##不要密码登录
<a href="https://s4.51cto.com/wyfs02/M01/95/C8/wKiom1kZnTGBFSRAAACGNZ1i2ac504.png" target="_blank"></a>
update mysql.user set Password=password('123') where User='root' ##更新root密码
ps aux | grep mysql ##过滤MySQL进程并结束
kill -9
systemctl start maraidb ##重启MySQL
3.数据库网页管理工具
yum install httpd php phy-mysql -y ##安装服务
<a href="https://s5.51cto.com/wyfs02/M01/95/C8/wKioL1kZnsvQLieVAAB3Y0CC1yE273.png" target="_blank"></a>
systemctl start httpd
systemctl enable httpd
systemctl stop firewalld
systemctl disable firewalld
tar jxf phpMyAdmin-3.4.0-all-languages.tar.bz2 -C /var/www/html ##解压文件到指定目录
mv phpMyAdmin-3.4.0-all-languages/ mysqladim ##重命名文件
<a href="https://s4.51cto.com/wyfs02/M00/95/C8/wKiom1kZoH-hLZhOAAA-gOru7G0316.png" target="_blank"></a>
cd mysqladim
cp -p config.sample.inc.php config.inc.php ##复制模板
<a href="https://s2.51cto.com/wyfs02/M00/95/C8/wKiom1kZoJrBeUKWAAA_qRQ3crs133.png" target="_blank"></a>
vim config.inc.php ##编辑配置文件
systemctl restart httpd
<a href="https://s3.51cto.com/wyfs02/M02/95/C8/wKioL1kZoNfDAstBAABN-E-T7FM457.png" target="_blank"></a>
**修改配置文件内容
**测试
<a href="https://s3.51cto.com/wyfs02/M01/95/C8/wKioL1kZoR3xjMAcAAD4_vDq554735.png" target="_blank"></a>
本文转自 red777 51CTO博客,原文链接:http://blog.51cto.com/12314711/1926015