客户用的数据库是mysql,而研发好的产品支持oracle,为了让客户掏腰包,我们必须把数据库环境从oracle转向mysql。我们在转换的过程中碰到了下面一些问题,希望能给同样遭遇的同仁们一些借鉴。如果我们在最初的设计、编码过程中注意数据库的移植性,这种情况
客户用的是mysql,而研发好的产品支持oracle,为了让客户掏腰包,我们必须把环境从oracle转向mysql。我们在转换的过程中碰到了下面一些问题,希望能给同样遭遇的同仁们一些借鉴。如果我们在最初的设计、编码过程中注意数据库的移植性,这种情况下可以完全不需要作额外工作。
一、数据库环境从oracle转向mysql碰到的问题。
因为逻辑不变,所以原则是不改应用程序代码,只改数据库表的创建/初始化sql。下面是我们碰到的问题以及解决办法。
1、 大小写敏感的区别(如果OS是linux)。
在oracle中一般情况下不区分大小写。有时候我们在使用oracle不注意大小写的问题,表名和字段名不加双引号是不区分大小写的,像这样:insert into tableName 和 insert into TABLENAME效果是一样的,用工具导出创建/数据初始化脚本,得到的结果一般表名和字段名转化成了大写。
但在MySQL中,所使用操作系统的大小写敏感性决定了数据库名和表名的大小写敏感性。数据库对应数据目录中的目录,数据库中的每个表至少对应数据库目录中的一个文件(也可能是多个,取决于存储引擎)。因此,使用数据库或表实际上是操纵这些文件(夹),所以使用操作系统的大小写敏感性决定了数据库名和表名的大小写敏感性。在以linux为内核的操作系统中是大小写敏感的。
解决的办法是把mysql的数据库名和oracle的大小写保持一致,表名与应用程序中sql字符串中的表名保持一致,如果应用程序中字段名用了双引号,那请把sql中的字段名大小写与双引号里的字符保持一致。如果你的应用程序所引用的表名、字段没有统一大小写,那麻烦就大了。
2、保留字的区别。
像sql语言的函数名(如:inteval,show)等是保留字。Oracle中保留字是可以作为表名和字段名,并且不影响使用,但mysql中保留字是不能作为表名和字段名,如果使用会报语法错误。
解决办法,把sql语句中的保留字用‘`’符号引起来,这个符号位于键盘的tab键上面;如果是字段名还有另外一种方法tablename.字段名。像这样:insert into tablename (id, `interval`) value(….. 或insert into tablename (id, tablename.inteval) value(….. 。
3、数据类型的区别。
在mysql中没有像oracle中的varchar2、number,mysql有与之对应的varchar、numeric,当然在oracle中没有mysql的time类型。
解决办法是替换。
4、自动增长类型的区别。
Oracle有sequence,mysql中没有,但有auto_increment属性。
解决办法是把Oracle中sequence转换成使用auto_increment属性,某些情况可能还有一种办法可以解决问题,新建一个独立的表用来专门记录自动增长型的数据。
5、索引长度限制的区别。
从MySQL 4.1.2开始,MyISAM和InnoDB表索引长度支持1000字节,也就是说索引字段的长度不能超过1000字节,如果超过会报这样的错: ERROR 1071 (42000): Specified key was too long; max key length is 1000 bytes。如果是UTF-8编码,相当于333个字符的长度(因为UTF8一个字符占3个字节)。Oracle的索引长度限制比mysql要宽松得多。
解决的办法就不必要多说了,要么改索引的定义,要么改字段的定义长度。

InnoDBBufferPool reduces disk I/O by caching data and indexing pages, improving database performance. Its working principle includes: 1. Data reading: Read data from BufferPool; 2. Data writing: After modifying the data, write to BufferPool and refresh it to disk regularly; 3. Cache management: Use the LRU algorithm to manage cache pages; 4. Reading mechanism: Load adjacent data pages in advance. By sizing the BufferPool and using multiple instances, database performance can be optimized.

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

MySQL is worth learning because it is a powerful open source database management system suitable for data storage, management and analysis. 1) MySQL is a relational database that uses SQL to operate data and is suitable for structured data management. 2) The SQL language is the key to interacting with MySQL and supports CRUD operations. 3) The working principle of MySQL includes client/server architecture, storage engine and query optimizer. 4) Basic usage includes creating databases and tables, and advanced usage involves joining tables using JOIN. 5) Common errors include syntax errors and permission issues, and debugging skills include checking syntax and using EXPLAIN commands. 6) Performance optimization involves the use of indexes, optimization of SQL statements and regular maintenance of databases.

MySQL is suitable for beginners to learn database skills. 1. Install MySQL server and client tools. 2. Understand basic SQL queries, such as SELECT. 3. Master data operations: create tables, insert, update, and delete data. 4. Learn advanced skills: subquery and window functions. 5. Debugging and optimization: Check syntax, use indexes, avoid SELECT*, and use LIMIT.

MySQL efficiently manages structured data through table structure and SQL query, and implements inter-table relationships through foreign keys. 1. Define the data format and type when creating a table. 2. Use foreign keys to establish relationships between tables. 3. Improve performance through indexing and query optimization. 4. Regularly backup and monitor databases to ensure data security and performance optimization.

MySQL is an open source relational database management system that is widely used in Web development. Its key features include: 1. Supports multiple storage engines, such as InnoDB and MyISAM, suitable for different scenarios; 2. Provides master-slave replication functions to facilitate load balancing and data backup; 3. Improve query efficiency through query optimization and index use.

SQL is used to interact with MySQL database to realize data addition, deletion, modification, inspection and database design. 1) SQL performs data operations through SELECT, INSERT, UPDATE, DELETE statements; 2) Use CREATE, ALTER, DROP statements for database design and management; 3) Complex queries and data analysis are implemented through SQL to improve business decision-making efficiency.

The basic operations of MySQL include creating databases, tables, and using SQL to perform CRUD operations on data. 1. Create a database: CREATEDATABASEmy_first_db; 2. Create a table: CREATETABLEbooks(idINTAUTO_INCREMENTPRIMARYKEY, titleVARCHAR(100)NOTNULL, authorVARCHAR(100)NOTNULL, published_yearINT); 3. Insert data: INSERTINTObooks(title, author, published_year)VA


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.