Home Database Mysql Tutorial 数据库环境从Oracle转向MySQL的注意事项

数据库环境从Oracle转向MySQL的注意事项

Jun 07, 2016 pm 05:53 PM
mysql oracle database Precautions

客户用的数据库是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要宽松得多。

  解决的办法就不必要多说了,要么改索引的定义,要么改字段的定义长度。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MySQL: An Introduction to the World's Most Popular Database MySQL: An Introduction to the World's Most Popular Database Apr 12, 2025 am 12:18 AM

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

Why Use MySQL? Benefits and Advantages Why Use MySQL? Benefits and Advantages Apr 12, 2025 am 12:17 AM

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's Place: Databases and Programming MySQL's Place: Databases and Programming Apr 13, 2025 am 12:18 AM

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

How to create oracle dynamic sql How to create oracle dynamic sql Apr 12, 2025 am 06:06 AM

SQL statements can be created and executed based on runtime input by using Oracle's dynamic SQL. The steps include: preparing an empty string variable to store dynamically generated SQL statements. Use the EXECUTE IMMEDIATE or PREPARE statement to compile and execute dynamic SQL statements. Use bind variable to pass user input or other dynamic values ​​to dynamic SQL. Use EXECUTE IMMEDIATE or EXECUTE to execute dynamic SQL statements.

How to create cursors in oracle loop How to create cursors in oracle loop Apr 12, 2025 am 06:18 AM

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

How to connect to the database of apache How to connect to the database of apache Apr 13, 2025 pm 01:03 PM

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

How to use triggers for oracle How to use triggers for oracle Apr 11, 2025 pm 11:57 PM

Triggers in Oracle are stored procedures used to automatically perform operations after a specific event (insert, update, or delete). They are used in a variety of scenarios, including data verification, auditing, and data maintenance. When creating a trigger, you need to specify the trigger name, association table, trigger event, and trigger time. There are two types of triggers: the BEFORE trigger is fired before the operation, and the AFTER trigger is fired after the operation. For example, the BEFORE INSERT trigger ensures that the age column of the inserted row is not negative.

How to stop oracle database How to stop oracle database Apr 12, 2025 am 06:12 AM

To stop an Oracle database, perform the following steps: 1. Connect to the database; 2. Shutdown immediately; 3. Shutdown abort completely.

See all articles