NO.14 数据库​的使用

需安装软件
yum install mysql mysql-server
yum install groupinstall -y mariadb mariadb-client


mysqladmin -uroot -predhat password westos                                修改本地mysql root密码

mysqladmin -uroot -predhat -h 192.168.0.188 password westos    修改远程192.168.0.188 mysql服务器 root密码
    
mysql_secure_installation                                                                第一次安装mysql以后通过这条命令可以对mysql进行设置

mysql -uroot -predhat                                                                       从本机登录mysql数据库

show databases;                                                                              显示数据库
use mysql;                                                                                        进入数据库
show tables;                                                                                     显示数据库中的表
desc user;                                                                                         查看user表的数据结构
flush privileges;                                                                                 刷新数据库信息
select host.user,password from user;                                               查询user表中的host,user,password字段


create database westos;                                                                   创建westos数据库
use westos;                            
create table linux(                                                                              创建表,username,password字段
username varchar(15) not null,
password varchar(15) not null
);
select * from mysql.user;                                                                    查询mysql库下的user表中的所以
alter table linux add age varchar(4);                                                  添加age字段到linux表中
ALTER TABLE linux DROP age                                                         删除age字段
ALTER TABLE linux ADD age  VARCHAR(5)  AFTER name             在name字段后添加字段age
            

show tables;
desc linux;

insert into linux values ('user1','passwd1');                                         在linux表中插入值为username = user1,password = password1
update linux set password=password('passwd2') where username=user1;    更新linux表中user1 的密码为password2
delete from linux where username=user1;                                                       删除linux表中user1的所以内容


grant select on  *.* to user1@localhost identified by 'passwd1';                      授权user1 密码为passwd1  并且只能在本地 查询数据库的所以内容
grant all on mysql.* to user2@'%' identified by 'passwd2';                               授权user2 密码为passwd2  可以从远程任意主机登录mysql 并且可以对mysql数据库任意操作


备份
/var/lib/mysql
mysqldump -uroot -predhat mysql > mysql.bak                                                备份mysql库到mysql.bak

mysql -uroot -predhat westos < mysql.bak                                                       恢复mysql.bak 到westos库



mysql 密码恢复
/etc/init.d/mysqld stop

mysqld_safe --skip-grant-tables &                                                                     跳过grant-tables授权表  不需要认证登录本地mysql数据库

update mysql.user set password=password('westos') where user='root';         更新mysql.user 表中条件为root用户的密码为加密westos

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值