-- 旧版本加密、解密(已弃用)
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 重启服务
-- 创建用户
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;
-- 指定表授权
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
-- 查看表空间物理文件的名称及大小
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
-- 生成清理所有表语句;
SELECT CONCAT('truncate TABLE ', TABLE_SCHEMA, '.', TABLE_NAME, ';')
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA IN ( '数据库名' );