Oracle与MySQL的差异和对比

Oracle与MySQL的差异和对比:配套hands-on参考脚本。

方便客户针对培训课件内容进行动手实践,加强理解。

---------------------------------
--  主题:Oracle与MySQL的差异和对比
--    一、MySQL的基础特性
--    二、重要特性差异对比
--    三、性能对比和优化技巧
--------------------------------

Hands-on场景环境准备@MySQL实例

--------------------------------
-- Hands-on场景环境准备@MySQL实例
--------------------------------
--Create db & user
CREATE DATABASE demodb;
CREATE USER 'alfred'@'localhost' IDENTIFIED BY 'alfred123';
GRANT ALL PRIVILEGES ON demodb.* TO 'alfred'@'localhost';
GRANT SELECT ON information_schema.* TO 'alfred'@'localhost';
FLUSH PRIVILEGES;


--Create tables
mysql -ualfred -palfred123 -Ddemodb


CREATE TABLE t (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50)
);


Insert into t(name) values ('Alfred'),('Mcdull');


commit;


select * from t;

Hands-on场景1:模拟MDL等待

--------------------------------
-- Hands-on场景1:模拟MDL等待
--------------------------------
--T1@ session1:TRX
begin;
select id from t;


--T2@ session2:DDL【被阻塞】
alter table t add age int;


--T3@ session3:Select【被阻塞】
select id from t;


--T4@ session1:TRX
commit;


--Check process & trx info
show processlist;
select * from information_schema.innodb_trx\G

Hands-on场景2:模拟死锁

--------------------------------
-- Hands-on场景2:模拟死锁
--------------------------------
--T1@ session1
begin;
update t set age=20 where id=1;


--T2@ session2
begin;
update t set age=18 where id=2;


--T3@ session1【被阻塞】
update t set age=18 where id=2;


--T4@ session2【数据库监测到死锁,事务回滚】
update t set age=20 where id=1;

Hands-on场景3:DB读取最小单位

--------------------------------
-- Hands-on场景3:DB读取最小单位
--------------------------------
--Oracle
show parameter db_block_size


--MySQL
show variables like 'innodb_page_size';

Hands-on场景4:查看SQL索引使用情况

--------------------------------
-- Hands-on场景4:查看SQL索引使用情况
--------------------------------
INSERT INTO t (name, age)
SELECT 
    CONCAT('Name_', FLOOR(RAND() * 10000)),
    FLOOR(RAND() * 100)
FROM
    (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t1
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t2
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t3
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t4
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t5
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t6
    CROSS JOIN (SELECT 1 AS dummy UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4) AS t7
LIMIT 10000;


explain select * from t where name='Alfred';


CREATE INDEX idx_name_age ON t(name, age);
CREATE INDEX idx_age ON t(age);
CREATE INDEX idx_name ON t(name);


explain select * from t where name='Alfred';


DROP INDEX idx_name_age ON t;


explain select * from t where name='Alfred';

Hands-on场景5:MySQL默认存储引擎、binlog、redolog信息确认

--------------------------------------------------------
-- Hands-on场景5:MySQL默认存储引擎、binlog、redolog信息确认
--------------------------------------------------------
show engines;
SELECT @@default_storage_engine;


ps -ef|grep mysql 
cd [--datadir]
ls -lrth mysql-bin.*
ls -lrth ib_logfile*


SHOW VARIABLES LIKE 'innodb_log_file_size';
SHOW VARIABLES LIKE 'innodb_log_files_in_group';

Hands-on场景6:查看MySQL业务表的详细状态信息

------------------------------------------
-- Hands-on场景6:查看MySQL业务表的详细状态信息
------------------------------------------
show table status like 't'\G
show index from t;
相关推荐
TypingLearn6 个月前
【.NET项目分享】免费开源的静态博客生成工具EasyBlog,5分钟拥有自己的博客
开源·.net·blog
ghostwritten6 个月前
Npm Install Docusaurus Demo【npm 安装 docusaurus 实践 】
前端·npm·node.js·web·blog
shandianchengzi7 个月前
【BUG】前端|GET _MG_0001.JPG 404 (Not Found),hexo博客搭建过程图片路径正确却找不到图片
前端·bug·hexo·blog
AlfredZhao8 个月前
难道AI不知道tnsnames.ora的instance_name配置吗?
blog
gc_229910 个月前
开源博客项目Blog .NET Core源码学习(8:EasyCaching使用浅析)
博客·blog·easycaching
Dyansts10 个月前
Docker安装开源Blog(Typecho)
linux·运维·docker·容器·blog
AiENG_071 年前
基于Hexo+GitHub Pages 的个人博客搭建
大数据·elasticsearch·github·hexo·个人博客·blog·静态站
丙睦1 年前
Linux超简单部署个人博客
blog
gc_22991 年前
开源博客项目Blog .NET Core源码学习(4:生成验证码)
c#·blog·开源博客