Mysql5.5使用裸设备存储

本文演示了如何在Mysql上使用裸设备存储innodb存储类型的表和索引来提升性能,包括创建LVM卷、修改my.cnf文件、初始化数据库、关闭数据库修改配置、重新启动数据库建表及插入数据测试,最后通过strings命令提取裸设备中的字符。重点在于性能优化和裸设备的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Mysql的innodb支持把表和索引存储在裸设备中,存储的I/O等待问题一直是影响数据库性能的关键,裸设备不需要经过文件系统I/O处理,因而在性能上有一定的提升,在使用rhel中的kvm虚拟机的时候有明显的感觉,使用裸设备+virtio的性能基本与物理机没差别;在Oracle中,裸设备从11g开始就不被支持,而10g rac的ocr和votedisk还必须使用裸设备存储,Oracle推荐使用ASM来提升存储的I/O性能,ASM支持条带,冗余和在线添加删除磁盘组等等高级功能,同时有具有一定的可管理性;相比之下Mysql的裸设备就比较脆弱,或许在分布式基础上,Mysql单实例的数据量还不需要用裸设备来提升I/0性能,下面来演示下如何在Mysql上使用裸设备存储innodb存储类型的表和索引

一:创建LVM卷,并使用raw来绑定,其中raw1-raw5为oracle的asm磁盘

  1. [root@dg53 ~]# lvcreate -n mydata -L 1G VolGroup00  
  2.   Volume Groups with the clustered attribute will be inaccessible.  
  3.   Logical volume "mydata" created  
  4.  
  5. [root@dg53 ~]# lvs  
  6.   Skipping clustered volume group new_vg  
  7.   LV       VG         Attr   LSize  Origin Snap%  Move Log Copy%  Convert  
  8.   LogVol00 VolGroup00 -wi-ao 29.28G                                        
  9.   LogVol01 VolGroup00 -wi-ao 29.28G                                        
  10.   mydata   VolGroup00 -wi-a-  1.00G   
  11.  
  12. [root@dg53 ~]# cat /etc/sysconfig/rawdevices   
  13. /dev/raw/raw1   /dev/sdb1  
  14. /dev/raw/raw2   /dev/sdc1  
  15. /dev/raw/raw3   /dev/sdd1  
  16. /dev/raw/raw4   /dev/sde1  
  17. /dev/raw/raw5   /dev/sdf1  
  18.  
  19. /dev/raw/raw6  /dev/VolGroup00/mydata  
  20.  
  21. [root@dg53 ~]# service rawdevices restart  
  22. Assigning devices:   
  23.            /dev/raw/raw1  -->   /dev/sdb1  
  24. /dev/raw/raw1:  bound to major 8, minor 17  
  25.            /dev/raw/raw2  -->   /dev/sdc1  
  26. /dev/raw/raw2:  bound to major 8, minor 33  
  27.            /dev/raw/raw3  -->   /dev/sdd1  
  28. /dev/raw/raw3:  bound to major 8, minor 49  
  29.            /dev/raw/raw4  -->   /dev/sde1  
  30. /dev/raw/raw4:  bound to major 8, minor 65  
  31.            /dev/raw/raw5  -->   /dev/sdf1  
  32. /dev/raw/raw5:  bound to major 8, minor 81  
  33.            /dev/raw/raw6  -->   /dev/VolGroup00/mydata  
  34. /dev/raw/raw6:  bound to major 253, minor 2  
  35. done  
  36.  
  37. [root@dg53 ~]# raw -qa  
  38. /dev/raw/raw1:  bound to major 8, minor 17  
  39. /dev/raw/raw2:  bound to major 8, minor 33  
  40. /dev/raw/raw3:  bound to major 8, minor 49  
  41. /dev/raw/raw4:  bound to major 8, minor 65  
  42. /dev/raw/raw5:  bound to major 8, minor 81  
  43. /dev/raw/raw6:  bound to major 253, minor 2  
  44.  
  45. [root@dg53 ~]# chown mysql.mysql /dev/raw/raw6  

二:修改my.cnf文件,在[mysqld]中添加如下两项!关于数据库的存储是否需要使用裸设备应当在数据库创建前规划好

  1. [root@dg53 ~]# grep 'innodb_data' /etc/my.cnf   
  2. innodb_data_home_dir =  
  3. innodb_data_file_path = /dev/raw/raw6:1Gnewraw 

三:初始化mysql数据库,启动mysql服务,在日志中可以看到格式化过程,在未将前面两项配置中的newraw改为raw之前,无法创建innodb类型的表

  1. [root@dg53 mysql-5.5.25]# sh ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.5.25/ --datadir=/mydata/  
  2.  
  3. [root@dg53 mysql-5.5.25]# service mysqld start  
  4. Starting MySQL....................[  OK  ]  
  5.  
  6. [root@dg53 ~]# tail -f /mydata/dg53.yang.com.err  
  7. 110601  9:55:51 InnoDB: The InnoDB memory heap is disabled  
  8. 110601  9:55:51 InnoDB: Mutexes and rw_locks use InnoDB's own implementation  
  9. 110601  9:55:51 InnoDB: Compressed tables use zlib 1.2.3  
  10. 110601  9:55:51 InnoDB: Initializing buffer pool, size = 128.0M  
  11. 110601  9:55:51 InnoDB: Completed initialization of buffer pool  
  12. InnoDB: The first specified data file /dev/raw/raw6 did not exist:  
  13. InnoDB: a new database to be created!  
  14. 110601  9:55:51  InnoDB: Setting file /dev/raw/raw6 size to 1024 MB  
  15. InnoDB: Database physically writes the file full: wait...  
  16. InnoDB: Progress in MB: 100 200 300 400 500 600 700 800 900 1000  
  17. 110601  9:56:09  InnoDB: Log file ./ib_logfile0 did not exist: new to be created  
  18. InnoDB: Setting log file ./ib_logfile0 size to 5 MB  
  19. InnoDB: Database physically writes the file full: wait...  
  20. 110601  9:56:09  InnoDB: Log file ./ib_logfile1 did not exist: new to be created  
  21. InnoDB: Setting log file ./ib_logfile1 size to 5 MB  
  22. InnoDB: Database physically writes the file full: wait...  
  23. InnoDB: Doublewrite buffer not found: creating new  
  24. InnoDB: Doublewrite buffer created  
  25. InnoDB: 127 rollback segment(s) active.  
  26. InnoDB: Creating foreign key constraint system tables  
  27. InnoDB: Foreign key constraint system tables created  
  28. 110601  9:56:10  InnoDB: Waiting for the background threads to start  
  29. 110601  9:56:11 InnoDB: 1.1.8 started; log sequence number 0  
  30. 110601  9:56:11 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306  
  31. 110601  9:56:11 [Note]   - '0.0.0.0' resolves to '0.0.0.0';  
  32. 110601  9:56:11 [Note] Server socket created on IP: '0.0.0.0'.  
  33. 110601  9:56:11 [Note] Event Scheduler: Loaded 0 events  
  34. 110601  9:56:11 [Note] /usr/local/mysql5.5.25/bin/mysqld: ready for connections.  
  35. Version: '5.5.25-log'  socket: '/tmp/mysql.sock'  port: 3306  Source distribution  
  36. InnoDB: A new raw disk partition was initialized:  
  37. InnoDB: we do not allow database modifications by the user.  
  38. InnoDB: Shut down mysqld and edit my.cnf so that newraw is replaced with raw.  
  39.  
  40. mysql> create database bbs;  
  41. Query OK, 1 row affected (0.00 sec)  
  42.  
  43. mysql> use bbs;  
  44. Database changed  
  45. mysql> create table user as select * from mysql.user;  
  46. ERROR 1005 (HY000): Can't create table 'bbs.user' (errno: -1) 

四:关闭数据库后,修改my.cnf文件,重新启动数据库,建表并插入数据测试

  1. [root@dg53 ~]# service mysqld stop  
  2. Shutting down MySQL.[  OK  ]  
  3.  
  4. [root@dg53 ~]# grep 'innodb_data' /etc/my.cnf   
  5. innodb_data_home_dir =  
  6. innodb_data_file_path = /dev/raw/raw6:1Graw  
  7.  
  8. [root@dg53 ~]# service mysqld start  
  9. Starting MySQL..[  OK  ]  
  10.  
  11. mysql> use bbs;  
  12. Database changed  
  13. mysql> create table user as select * from mysql.user;  
  14. Query OK, 6 rows affected (0.05 sec)  
  15. Records: 6  Duplicates: 0  Warnings: 0  
  16.  
  17. mysql> insert into user select * from user;  
  18. Query OK, 6 rows affected (0.01 sec)  
  19. Records: 6  Duplicates: 0  Warnings: 0  
  20.  
  21. mysql> insert into user select * from user;  
  22. Query OK, 12 rows affected (0.01 sec)  
  23. Records: 12  Duplicates: 0  Warnings: 0  
  24.  
  25. mysql> insert into user select * from user;  
  26. Query OK, 24 rows affected (0.01 sec)  
  27. Records: 24  Duplicates: 0  Warnings: 0  
  28.  
  29. mysql> insert into user select * from user;  
  30. Query OK, 48 rows affected (0.00 sec)  
  31. Records: 48  Duplicates: 0  Warnings: 0  
  32.  
  33. mysql> insert into user select * from user;  
  34. Query OK, 96 rows affected (0.05 sec)  
  35. Records: 96  Duplicates: 0  Warnings: 0  
  36.  
  37. mysql> insert into user select * from user;  
  38. Query OK, 192 rows affected (0.01 sec)  
  39. Records: 192  Duplicates: 0  Warnings: 0  
  40.  
  41. mysql> insert into user select * from user;  
  42. Query OK, 384 rows affected (0.02 sec)  
  43. Records: 384  Duplicates: 0  Warnings: 0  
  44.  
  45. mysql> commit;  
  46. Query OK, 0 rows affected (0.00 sec)  
  47.  
  48. mysql> create index i_user_host on user(host);  
  49. Query OK, 0 rows affected (0.16 sec)  
  50. Records: 0  Duplicates: 0  Warnings: 0 

五:使用strings命令萃取裸设备中可打印的字符

  1. [root@dg53 ~]# strings /dev/raw/raw6 |grep dg53.yang.com |head  
  2. Vdg53.yang.com                                                                                                          
  3. rdg53.yang.com                                               root                                                       
  4. dg53.yang.com                                                                                                          
  5. dg53.yang.com                                               root                                                       
  6. dg53.yang.com                                                                                                          
  7. dg53.yang.com                                               root                                                       
  8. Rdg53.yang.com                                                                                                          
  9. dg53.yang.com                                               root                                                       
  10. Vdg53.yang.com                                                                                                          
  11. rdg53.yang.com                                               root   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值