The difference between Mysql and Oracle

One, the difference between mysql and oracle macro:

1. Both mysql and oracle are relational databases and are used on various platforms. MySQL was originally developed by a Swedish company, but it was later acquired by Sun, and then Sun was acquired by Oracle. So now it can be said that MySQL belongs to Oracle. MySQL is open source for free, while Oracle is charged and the price is very high. .

  • mysql default port: 3306, default user: root
  • oracle default port: 1521, default user: system

The installation and uninstallation of mysql is very simple, oracle is very troublesome, and the space used for installation is also very different. After mysql is installed, it is almost one or two hundred megabytes, while oracle has about 3G, and when used, oracle occupies a particularly large memory space and other Machine performance.

  • mysql login: mysql -hlocalhost -uroot -p密码(h: host, u: user, p: password)
  • Oracle login: sqlplus user_name/password@IP:port/instance_name;(The IP address, port number, and instance name can be written in a TNS file to get an alias. Just enter this alias when logging in)

At the beginning stage, graphical tools, mysql can use Navicat, Oracle generally uses PLSQL, or sqlyog, etc.;

  • MySQL has fewer management tools, and the installation of management tools under Linux sometimes requires the installation of additional packages (phpmyadmin, etc), which is somewhat complicated.
  • Oracle has multiple mature command lines, graphical interfaces, web management tools, and many third-party management tools, making management extremely convenient and efficient.

Oracle supports large concurrency and high traffic volume. It is the best tool for OLTP.

2. The hierarchical structure of the database:

  • mysql: The default user is root, and many databases can be created under the user, and there are many tables under each database. Generally, the default user is used, and multiple users will not be created;
  • oracle: Create a database. There are many users under the database: sys, system, scott, etc. There are many tables under different users. Generally, only one database is created.

2. Operation difference:

1. Table field types in the database:

  • mysql: Numerical types such as int, float, double, varchar, char character types, date, datetime, time, year, timestamp and other date types.
  • oracle: number (numerical type), varchar2, varchar, char (character type), date (date type), etc...

Among them, char(2) is defined as such. This unit represents two bytes in Oracle and two characters in MySQL.
Where varchar is in mysql, you must give the length such as varchar(10), otherwise an error occurs when inserting.

2. Primary key:

  • MySQL generally uses the automatic growth type. You only need to specify the primary key of the table when creating a table. When auto incrementinserting a record, you do not need to specify the primary key value of the record, and mysql will automatically grow.
  • Oracle does not have an automatic growth type. The primary key generally uses a sequence. When inserting a record, assign the next value of the sequence number to the field, but the ORM framework only needs to be a native primary key generation strategy.

3. Single quotation mark processing: Double quotation marks can be used to wrap strings in mysql, and single quotation marks can only be used to wrap strings in Oracle.

4. Paging processing:

  • mysql is used directly in SQL statements to limitachieve paging
  • Oracle needs to use fake ROWNUM and nested queries

5. Commit the transaction:

  • mysql is automatically submitted by default and can be modified to manual submission
  • Oracle does not automatically submit by default, you need to submit manually, you need to write commitinstructions or click a commitbutton.

6. Support for transactions: MySQL supports transactions only under the condition of the innodb storage engine's ramming machine, while Oracle fully supports transactions.

7. Transaction isolation level:

  • mysql is the isolation level of read commited, and oracle is the isolation level of repeatable read;
  • At the same time, both support serializable serialized transaction isolation level, which can achieve the highest level of read consistency. After each session is submitted, other sessions can see the submitted changes;
  • Oracle achieves read consistency by constructing multi-version data blocks in the undo table space. When each session is queried, if the corresponding data block changes, oracle will construct the old data block for the session in the undo space. ;
  • MySQL does not have a mechanism for constructing multi-version data similar to Oracle. It only supports the isolation level of read commited. When one session reads data, other sessions cannot change the data, but can insert data at the end of the table; when the session updates data, add row It locks, other sessions cannot access the data.

8. Concurrency:

  • MySQL mainly uses table-level locks, and the granularity of resource locks is very large. If a session locks a table for too long, other sessions cannot update the data in this table. Although the Innodb engine table can use row-level locks, the mechanism of this row-level lock depends on the index of the table. If the table does not have an index, or the SQL statement does not use an index, then the table-level lock is still used;
  • Oracle uses row-level locks. The granularity of resource locks is much smaller. It just locks the resources required by SQL, and the locks are on the data rows in the database and do not rely on indexes. Therefore, Oracle's support for concurrency is much better.

9. Logical backup: During mysql logical backup, data must be locked to ensure that the backed up data is consistent, which affects the normal use of dml for business. Oracle logical backup does not lock data, and the backup data is consistent.

10. Copy:

  • mysql: The configuration of the replication server is very simple, but when the master database has a problem, the slave database may lose certain data, and you need to manually switch from the database to the master database;
  • oracle: There are both heap or pull traditional data replication, and dataguard's dual or multi-machine disaster recovery mechanism. When the main library has a problem, it can automatically switch the standby library to the main library, but the configuration management is more complicated.

11. Performance diagnosis:

  • mysql has fewer diagnostic and tuning methods, mainly slow query logs;
  • Oracle has a variety of mature performance diagnosis and tuning tools, which can realize many automatic analysis and diagnosis functions. Such as awr, addm, sqltrace, tkproof, etc.

12. Persistence of saved data:

  • mysql submits SQL statements by default, but if there is a problem with db or host restart during the update process, data may be lost;
  • Oracle writes the submitted sql operation into the online online log file first, saves it on the hard disk, and can restore it at any time.

13. Hot backup:

  • Oracle has a mature hot backup tool rman, which does not affect users' use of the database. Even if the backed-up database is inconsistent, you can use the archive log and online redo log for consistent recovery during recovery.
  • mysql:
    • myisam engine: When using mysqlhostcopy that comes with mysql for hot backup, you need to add a read lock to the table, which affects the dml operation;
    • Innodb engine: It will back up innodb tables and indexes, but it will not back up .frmfiles. When using ibbackup to back up, there will be a log file to record the data changes during the backup period. Therefore, it is not necessary to lock the table and not affect other users to use the database, but this Tools are charged.
    • innobackup is a script used in conjunction with ibbackup, it will assist in .frmthe backup of files.

13. Date conversion:

  • Date conversion dateformat()function in mysql ;
  • oracle with to_date()the to_char()two functions.

Guess you like

Origin blog.csdn.net/weixin_44296929/article/details/108705913