• MySQL-Encryption.sql MySQL 数据加密、解密
    netnr 2022-07-05 49
    -- 旧版本加密、解密(已弃用)
    INSERT INTO users (username, password) VALUES ('john', ENCODE('guessme', 'salt')); -- 写入加密
    SELECT username, DECODE(password,'salt') AS password FROM users WHERE username = 'john'; -- 查询解密
    
    -- 新版本加密、解密(安全级别、性能高)
    INSERT INTO users (username, password) VALUES ('steven', aes_encrypt('password', 'salt')); -- 写入加密
    SELECT username, aes_decrypt(password,'salt') AS password FROM users WHERE username = 'steven';  -- 查询解密
    
    SET block_encryption_mode = 'aes-256-cbc'; -- 修改加密模式
    -- 或添加到配置文件 /etc/my.cnf 重启服务
  • PostgreSQL-Manager.sql PostgreSQL 用户授权
    netnr 2022-02-08 326
    -- 创建用户
    CREATE USER dbUser WITH PASSWORD 'Abc123....';
    
    -- 数据库授权用户,此时用户还是没有读写权限,需要授权表
    GRANT ALL PRIVILEGES ON DATABASE dbName TO dbUser;
    
    -- 当前数据库下 public schema 的表都授权给 dbUser
    GRANT ALL PRIVILEGES ON all tables in schema public TO dbUser;
    
    -- 指定表授权
  • Clear_SQLServer_Log.sql SQLServer 清理日志文件
    netnr 2020-06-01 3
    USE [master]
    GO
    ALTER DATABASE DBNAME SET RECOVERY SIMPLE WITH NO_WAIT
    GO
    ALTER DATABASE DBNAME SET RECOVERY SIMPLE   -- 设置简单模式
    GO
    USE DBNAME
    GO
    DBCC SHRINKFILE (N'DBNAME_log' , 2, TRUNCATEONLY)  -- 设置压缩后的日志大小为 2M
    GO
  • OracleManager.sql Oracle 表空间、用户、角色权限的管理
    netnr 2020-01-10 328
    -- 查看表空间物理文件的名称及大小
    SELECT tablespace_name, file_id, file_name, round(bytes / (1024 * 1024), 2) total_space
    FROM dba_data_files ORDER BY tablespace_name;
    
    -- 表空间占用情况
    SELECT a.segment_name, b.table_name, sum(a.bytes)/ 1024 / 1024 AS mb
    FROM dba_segments a LEFT JOIN dba_lobs b ON a.segment_name = b.segment_name
    WHERE a.tablespace_name = 'DSPACE' GROUP BY a.segment_name, b.table_name ORDER BY mb DESC;
    
    -- 查询所有用户所对应的表空间,有dba权限的帐号,如sys,system
  • drop.sql SqlServer 删除所有表
    netnr 2018-09-21 6
    -- 删除所有表
    DECLARE @sql VARCHAR(8000);
    WHILE EXISTS (SELECT name FROM sysobjects WHERE type = 'U')
    BEGIN
        SELECT @sql = 'DROP TABLE ' + name
        FROM sysobjects
        WHERE (type = 'U');
    
        PRINT (@sql);
  • truncate.sql truncate 清空所有表,mysql 数据库
    netnr 2018-09-21 8
    -- 生成清理所有表语句;
    SELECT CONCAT('truncate TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';')
    FROM INFORMATION_SCHEMA.TABLES
    WHERE TABLE_SCHEMA IN ( '数据库名' );