博客
关于我
MySQL-【1】配置
阅读量:791 次
发布时间: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 存储过程每隔一段时间执行一次
查看>>
mysql 存在update不存在insert
查看>>
Mysql 学习总结(86)—— Mysql 的 JSON 数据类型正确使用姿势
查看>>
Mysql 学习总结(87)—— Mysql 执行计划(Explain)再总结
查看>>
Mysql 学习总结(88)—— Mysql 官方为什么不推荐用雪花 id 和 uuid 做 MySQL 主键
查看>>
Mysql 学习总结(89)—— Mysql 库表容量统计
查看>>
mysql 实现主从复制/主从同步
查看>>
mysql 审核_审核MySQL数据库上的登录
查看>>
mysql 导入 sql 文件时 ERROR 1046 (3D000) no database selected 错误的解决
查看>>
mysql 导入导出大文件
查看>>
MySQL 导出数据
查看>>
mysql 将null转代为0
查看>>
mysql 常用
查看>>
MySQL 常用列类型
查看>>
mysql 常用命令
查看>>
Mysql 常见ALTER TABLE操作
查看>>
MySQL 常见的 9 种优化方法
查看>>
MySQL 常见的开放性问题
查看>>
Mysql 常见错误
查看>>
mysql 常见问题
查看>>