数据库环境从Oracle转向MySQL的注意事项
客户用的数据库是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要宽松得多。
解决的办法就不必要多说了,要么改索引的定义,要么改字段的定义长度。

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

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.

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
