博客
关于我
MySQL-【1】配置
阅读量:798 次
发布时间:2023-02-11

本文共 1218 字,大约阅读时间需要 4 分钟。

数据库操作指南

1. 数据库基操

在数据库中操作是日常工作的重要部分,以下是常用的数据库操作命令:

1.1 创建/删除/使用数据库

  • 创建数据库
    create database mydatabase;
  • 显示数据库
    show databases;
  • 删除数据库
    drop database mydatabase;
  • 使用数据库
    use mydatabase;

1.2 数据表操作

  • 创建数据表
    create table mytable(  id int(4) not null primary key auto_increment,  name char(255),  score float(8,2));
  • 删除数据表
    drop table mytable;
  • 插入数据
    insert into mytable (id,name,score) values(1,"tom",93.65);
  • 查询数据
    select * from mytable;
  • 查询高分数据
    select * from mytable where score > 60;

1.3 数据表高级操作

  • 修改表名
    rename mytable to newtable;
  • 添加字段
    alter table mytable2 add brother int(4) default 0;
  • 批量删除
    delete from mytable where id in (20,21,22,23);

2. 数据库安全

2.1 MySQL安全设置

  • 默认访问权限
    use mysqlselect user, host from user;
  • 删除危险账户
    delete from user where host="%";
  • 修改账户权限
    create user 'root'@'localhost' identified by '密码';grant all privileges on *.* to root@IP地址;flush privileges;
  • 重启服务
    service mysqld restart

2.2 忘记密码处理

  • 修改密码
    update user set password="新密码" where user="用户名";

3. 数据库定时备份

3.1 自动备份脚本

  • 脚本内容

#!/bin/bashcd /usr/bin && ./mysqldump -hlocalhost -u"数据库名称" -p"数据库密码" mydb > /root/DBBackup/$(date +%Y%m%d).bakcd /root

- **执行权限**:  ```bashchmod 777 your.sh
  • 定时执行
    crontab -e

    添加以下行:

    * 23:59 * * * /root/your.sh

通过以上操作,您可以轻松管理数据库,确保数据安全和稳定性。

转载地址:http://acbfk.baihongyu.com/

你可能感兴趣的文章
MySQL 的存储引擎有哪些?为什么常用InnoDB?
查看>>
mysql 索引
查看>>
MySQL 索引失效的 15 种场景!
查看>>
MySQL 索引深入解析及优化策略
查看>>
MySQL 索引的面试题总结
查看>>
mysql 索引类型以及创建
查看>>
MySQL 索引连环问题,你能答对几个?
查看>>
Mysql 索引问题集锦
查看>>
Mysql 纵表转换为横表
查看>>
mysql 编译安装 window篇
查看>>
mysql 网络目录_联机目录数据库
查看>>
MySQL 聚簇索引&&二级索引&&辅助索引
查看>>
Mysql 脏页 脏读 脏数据
查看>>
mysql 自增id和UUID做主键性能分析,及最优方案
查看>>
Mysql 自定义函数
查看>>
mysql 行转列 列转行
查看>>
Mysql 表分区
查看>>
mysql 表的操作
查看>>
mysql 视图,视图更新删除
查看>>
MySQL 触发器
查看>>