1.安装数据库
yum install mariadb-server -y
##安装mariadb数据库
systemctl start mariadb
##开启服务
netstat -antlpe | grep mysql
##查看mysql端口
vim /etc/my.cnf
##修改数据库配置文件
skip -networking 1
##跳过网络:是
systemctl restart mariadb
##重启服务
mysql_secure_installation
##设置mysql加密
mysql
##登录,加密后登陆显示denied
2.登录
mysql -uroot -pwestos
##-u表示指定用户,-p表示指定此用户密码
3.查询
show databases;
##显示数据库
use mysql;
##进入mysql数据库
show tables;
##显示当前库中表的名称
select * from user;
##查询user表中的所有内容(*可以用此表中任何字段代替)
desc user;
##查询user表的结构(显示所有字段名称)
4.数据库及表的建立
create database westos;
##创建westos库
create table linux(
username varchar(15) not null, ##username字段 varchar(15)字符长度最大15个,not null不能为空
password varchar(15) not null
);
##创建linux表,并且linux表含有两个字段,username password
insert into linux values ('user1','passwd1');
##向linux表中插入数据,username字段的数据为user1
insert into linux values ('user1',password('passwd1'));
##插入的password字段是用password加密过的
desc linux;
##查询linux表的结构(显示所有字段名称)
select * from linux;
##查询linux表中的所有内容(*可以用此表中任何字段代替)
5.更新数据库信息
update linux set password=password('passwd2') where username='user1';
##更新user1的密码
delete from linux where username='user1';
##删除user1信息
alter table linux class age varchar(20) not null;
##添加class字段到linux表最后一列
alter table linux add type varchar(20) not null after name;
##添加type字段到name字段之后
alter table linux drop class;
##删除class字段
update linux set password=password('passwd2') where( username='user1'or username='user2' );
##更新user1的密码和user2的密码
6.删除数据库
delete from linux where username='user1';
##删除user1的数据从linux表中
drop table linux;
##删除linux表
drop database westos;
##删除westos库
7.数据库的备份
mysqldump -uroot -pwestos --all-database
##备份所有表中的所有数据
mysqldump -uroot -pwestos --all-database --no-data
##备份所有表,但不备份数据
mysqldump -uroot -pwestos westos
##备份westos库
mysqldump -uroot -pwestos westos > /mnt/westos.sql
##备份westos库并将数据保存到/mnt/westos.sql中
mysqldump -uroot -pwestos westos linux > /mnt/linux.sql
##备份westos中的linux表
mysql -uroot -pwestos westos < /mnt/westos.sql
##将数据导入westos
8.用户授权
vim /etc/my.cnf
skip-networking=0
##跳过网络:否
登录时显示无法连接
本地登录后无法显示数据库文件,因为没有授权
create user lee@localhost identified by 'luu';
##创建luu用户,此用户只能通过本机登录
create user lee@'%' identified by 'luu';
##创建luu用户,此用户可以通过网络登录
select User,Host from mysql.user
##查看表中User和Host内容
grant insert,update,delete,select on westos.test to luu@localhost
##用户授权
grant select on westos.* to luu@'%'
##用户授权
show grants for luu@'%'
##查看用户授权
revoke delete on westos.test from luu@localhost;
##去除用户授权权力
drop user luu@'%' ##删除用户
9.密码修改
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
##登陆测试
10.数据库的网页管理工具
yum install httpd php php-mysql -y
##安装php,httpd,php-mysql网页管理工具
systemctl start httpd
##开启httpd
systemctl stop firewalld
##关闭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
##改名为mysqladmin
cd mysqladmin
cp -p config.sample.inc.php config.inc.php
##复制模板
vim config.inc.php
##编辑配置文件
17 $cfg['blowfish_secret'] = 'mysql'; /*YOU MUST FILL IN THIS FOR...
##修改17行,‘’间加入mysql
systemctl restart httpd
##重启
测试:
访问
http://172.25.254.100/mysqladmin