数据库
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