第三本书 数据库

                                                                          数据库

1.数据库的安装准备

 yum install mariadb-server –y

systemctl startmariadb

vim /etc/my.cnf

###在【mysqld】中插入

skip-networking=1       ##禁止ip远程用户访问数据库


mysql_secure_installation

 

mysql –uroot –pwestos


2.数据库的基本sql语句操作

(1)登录

Mysql –uroot –pwestos

(2)查询

show databases;         ##显示数据库

use mysql;        ##进入mysql库

show tables;           ##显示当前库中标的名称

select  * from user;   ##查询user表中的所有内容

desc user;         ##查询user表的结构

3.数据库表的建立

create  database westos;             ##创建westos库

create  table linux( username varchar(15) notnull,password varchar(15) not null);##创建linux表,表中含有两个字段username.password,字符最大长度15不能为空


insert into linux values (‘user1’,password(’passwd1’) ); ##插入password字段的数据加密


4.更新数据库信息

update linux setpassword=password(‘passwd2’)  where username=’user1’;

##将user1password字段更新为加密passwd2


alter tablelinux add age varchar(5) after name;   ##在linux表中添加新字段age在name字段后

alter tablelinux drop age;    ##删除linux表中的age字段


5.删除数据库

delete fromlinux where username=’user1’;     ##从linux表中username字段中删除user1数据


drop tablelinux;         ##删除linux表

drop databasewestos;   ##删除westos库

6.数据库的备份

mysqldump –uroot –pwestos –all-database   ##备份表中所有数据

mysqldump –uroot –pwestos –all-database –no-data  ##备份所有表不备份数据

mysqldump –uroot –pwestos westos > /mnt/westos.sql ##备份westos库并输出到/mnt/westos.sql

##在数据库中删除westos库后重新建立

mysql –uroot –pwestos–e “create database westos;”

mysql –uroot –pwestoswestos < /mnt/westos.sql  ##把数据导入westos库


7.用户授权

create userzxh@localhost identified by ‘zxh’;  ##建立本地用户zxh@localhost,密码为zxh

create user zxh@’%’identified by ‘zxh’;  ##建立远程用户zxh@’%’,密码为zxh

grantinsert.update,delete on westos.linux to zxh@localhost;  ##给予本地用户zxh@localhost westos库中的linux表权限

grant select onwestos.linux to zxh@’%’  ##给予远程用户在linux表的select权限

show grants forzxh@’%’   ##查看用户权限


revoke delete onwestos.linux  from  zxh@localhost ;  #去除用户权限

drop user zxh@’%’   ##删除用户

测试远程用户zxh@’%’时要在/etc/my.cnf中更改--skip-networking=0


8.密码修改

mysqladmin –uroot–pwestos password zxh    ##修改超级用户密码为zxh


##当超级用户密码忘记

vim/etc/my.cnf 

##在【mysqld】中插入

--skip-grant-tables##不用密码登录mysql


mysql

updatemysql.user set Password=password(‘123’) where User=’root’;  ##更新超级用户密码为123


ps aux | grepmysql     ##过滤mysql所有进程

kill -9 mysqlpid

systemctl startmariadb

mysql –uroot –p123


9.数据库中php安装测试

(1)安装

yun install phppjp-mysql –y

systemctl starthttpd

systemctl enablehttpd

systemctl stopfirewalld

systemctldisable firewalld

(2)调配

tar jxfphpMyadmin-3.4.0-all-languages.tar.bz2 -C  /var/www/html  ##解压到html地址

mvphpMyadmin-3.4.0-all-languages/ mysqladmin  ##更改名称为mysqladmin

cd mysqladmin


cp –pconfig.sample.inc.php config.inc.php

vim  config.inc.php  #其中调配只需插入mysql

 

systemctl restart  httpd

 

(3)测试

http://172.25.254.130/mysqladmin

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值