NO.14 数据库​的使用

    xiaoxiao2021-03-25  95

    需安装软件 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
    转载请注明原文地址: https://ju.6miu.com/read-22251.html

    最新回复(0)