Home Database Mysql Tutorial Detailed explanation of MariaDB (MySQL) creation, deletion, selection and data type usage_MySQL

Detailed explanation of MariaDB (MySQL) creation, deletion, selection and data type usage_MySQL

Oct 09, 2016 am 08:33 AM
mariadb database

1. Introduction to MariaDB (the introduction to MySQL is skipped)

          MariaDB database management system is a branch of MySQL, mainly maintained by the open source community, and licensed under GPL. The purpose of MariaDB is to be fully compatible with MySQL, including API and command line, so that it can easily become a replacement for MySQL. In terms of storage engine, XtraDB (English: XtraDB) is used instead of MySQL's InnoDB. MariaDB was developed by Michael Widenius (English: Michael Widenius), the founder of MySQL. He had earlier sold the company he founded, MySQL AB, to SUN for US$1 billion. Since then, as SUN was acquired by Oracle, MySQL The ownership also fell into the hands of Oracle. The name MariaDB comes from the name of Michael Widenius' daughter Maria.

        MariaDB The transaction-based Maria storage engine, which replaces MySQL’s MyISAM storage engine, uses Percona’s XtraDB, a variant of InnoDB that the developers of the fork hope to provide access to the upcoming MySQL 5.4 InnoDB performance. This version also includes PrimeBase XT (PBXT) and FederatedX storage engines.

2. Detailed explanation of MariaDB creation, deletion, selection and data type usage (Note: This article demonstrates root privileges)

(1)MariaDB creates database

1.1: Use mysqladmin to create a database

[root@test01 10.19.166.166 ~ ] 
# mysqladmin -u root -p create testdb1
Enter password:  // 此处填写MariaDB数据库的密码
 
[root@test01 10.19.166.166 ~ ] 
# mysql
 
MariaDB [(none)]> show databases;
+--------------------+
| Database      |
+--------------------+
| hellodb      |
| information_schema |
| mydb        |
| mysql       |
| performance_schema |
| test        |
| testdb       |
| testdb1      |<---创建的好的库
+--------------------+
Copy after login

1.2: Log in to MariaDB library to create

MariaDB [(none)]> create database testdb2;
Query OK, 1 row affected (0.00 sec)
 
MariaDB [(none)]> show databases;
+--------------------+
| Database      |
+--------------------+
| hellodb      |
| information_schema |
| mydb        |
| mysql       |
| performance_schema |
| test        |
| testdb       |
| testdb1      |
| testdb2      |<---创建好的库
+--------------------+
Copy after login

(2) MariaDB delete database

2.1: Use mysqladmin to delete the database

[root@test01 10.19.166.166 ~ ] 
# mysqladmin -u root -p drop testdb1
Enter password: //输入数据库密码
 
//执行完上面的删除命令后,会出现一个提示框,提示是否确认删除此数据库
Dropping the database is potentially a very bad thing to do.
Any data stored in the database will be destroyed.
 
Do you really want to drop the 'testdb1' database [y/N] y  //删除
Database "testdb1" dropped
Copy after login

Log in to view

MariaDB [(none)]> show databases; //确认testdb1已被删除 
+--------------------+
| Database      |
+--------------------+
| hellodb      |
| information_schema |
| mydb        |
| mysql       |
| performance_schema |
| test        |
| testdb       |
| testdb2      |
+--------------------+
Copy after login

2.2: Log in to MariaDB library to delete

MariaDB [(none)]> drop database testdb2;
Query OK, 0 rows affected (0.00 sec)
 
MariaDB [(none)]> show databases; //确认testdb2已被删除
+--------------------+
| Database      |
+--------------------+
| hellodb      |
| information_schema |
| mydb        |
| mysql       |
| performance_schema |
| test        |
| testdb       |
+--------------------+
Copy after login

(3) MariaDB selects the database and views all tables under the selected database

MariaDB [(none)]> show databases; //查看所有库
+--------------------+
| Database      |
+--------------------+
| hellodb      |
| information_schema |
| mydb        |
| mysql       |
| performance_schema |
| test        |
| testdb       |
+--------------------+
7 rows in set (0.00 sec)
 
MariaDB [(none)]> use mydb //选择mydb数据库 
Database changed  
MariaDB [mydb]> show tables;  //查看mydb数据库下面所有表信息
+----------------+
| Tables_in_mydb |
+----------------+
| ssc      |
| t1       |
| tb2      |
| tb4      |
| tb5      |
+----------------+
5 rows in set (0.00 sec)
Copy after login

(4) MariaDB data types
The types of data fields defined in MariaDB are very important for database optimization
MariaDB supports multiple types, which can be roughly divided into three categories: numerical values, date/time, and strings (character types)

4.1 Numeric type

Type Size Range (signed) Range (unsigned) Use
TINYINT 1 byte (-128,127) (0,255) Small integer value
SMALLINT 2 bytes (-32 768,32767) (0,65 535) Large integer value
MEDIUMINT 3 bytes (-8 388 608, 8 388 607) (0,16 777 215) Large integer value
INT or INTEGER 4 bytes (-2 147 483 648, 2 147 483 647) (0,4 294 967 295) Large integer value
BIGINT 8 bytes (-9 233 372 036 854 775 808, 9 223 372 036 854 775 807) (0,18 446 744 073 709 551 615) Extremely large integer value
FLOAT 4 bytes (-3.402 823 466 E+38, 1.175 494 351 E-38), 0, (1.175 494 351 E-38, 3.402 823 466 351 E+38) 0, (1.175 494 351 E-38, 3.402 823 466 E+38) Single precision
Floating point value
DOUBLE 8 bytes (1.797 693 134 862 315 7 E+308, 2.225 073 858 507 201 4 E-308), 0, (2.225 073 858 507 201 4 E-308, 1.797 693 134 862 315 7 E+3 08) 0,(2.225 073 858 507 201 4 E-308,1.797 693 134 862 315 7 E+308) Double precision
Floating point value
DECIMAL For DECIMAL(M,D), if M>D, it is M+2 otherwise it is D+2 Depends on the values ​​of M and D Depends on the values ​​of M and D Decimal value

4.2 Date and time types

Date and time types representing time values ​​are DATETIME, DATE, TIMESTAMP, TIME and YEAR.
Each time type has a range of valid values ​​and a "zero" value, which is used when specifying an illegal value that MySQL cannot represent.
The TIMESTAMP type has proprietary automatic update features, which will be described later.

Type Size (bytes) Scope Format Use
DATE 3 1000-01-01/9999-12-31 YYYY-MM-DD Date value
TIME 3 '-838:59:59'/'838:59:59' HH:MM:SS Time value or duration
YEAR 1 1901/2155 YYYY Year value
DATETIME 8 1000-01-01 00:00:00/9999-12-31 23:59:59 YYYY-MM-DD HH:MM:SS Mixed date and time values
TIMESTAMP 8 1970-01-01 00:00:00/Sometime in 2037 YYYYMMDDHHMMSS Mixed date and time values, timestamps

​​​ 4.3 String type

String types refer to CHAR, VARCHAR, BINARY, VARBINARY, BLOB, TEXT, ENUM and SET. This section describes how these types work and how to use them in queries.

Type Size Use
CHAR 0-255 bytes Fixed length string
VARCHAR 0-255 bytes Variable length string
TINYBLOB 0-255 bytes Binary string of no more than 255 characters
TINYTEXT 0-255 bytes Short text string
BLOB 0-65 535 bytes Long text data in binary form
TEXT 0-65 535 bytes Long text data
MEDIUMBLOB 0-16 777 215 bytes Medium length text data in binary form
MEDIUMTEXT 0-16 777 215 bytes Medium length text data
LOGNGBLOB 0-4 294 967 295 bytes Extremely large text data in binary form
LONGTEXT 0-4 294 967 295 bytes Very large text data

CHAR and VARCHAR types are similar, but they are saved and retrieved differently. They also differ in terms of their maximum length and whether trailing spaces are preserved. No case conversion is performed during storage or retrieval.

BINARY and VARBINARY classes are similar to CHAR and VARCHAR, except that they contain binary strings instead of non-binary strings. That is, they contain byte strings rather than character strings. This means that they do not have a character set, and sorting and comparison are based on the numeric value of the column value bytes.
BLOB is a binary large object that can hold a variable amount of data. There are 4 BLOB types: TINYBLOB, BLOB, MEDIUMBLOB and LONGBLOB. They only differ in the maximum length they can hold a value.

There are 4 TEXT types: TINYTEXT, TEXT, MEDIUMTEXT and LONGTEXT. These correspond to 4 BLOB types, with the same maximum length and storage requirements.

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

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks 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)

Hot Topics

Java Tutorial
1666
14
PHP Tutorial
1273
29
C# Tutorial
1252
24
iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to use database callback functions in Golang? How to use database callback functions in Golang? Jun 03, 2024 pm 02:20 PM

Using the database callback function in Golang can achieve: executing custom code after the specified database operation is completed. Add custom behavior through separate functions without writing additional code. Callback functions are available for insert, update, delete, and query operations. You must use the sql.Exec, sql.QueryRow, or sql.Query function to use the callback function.

How to save JSON data to database in Golang? How to save JSON data to database in Golang? Jun 06, 2024 am 11:24 AM

JSON data can be saved into a MySQL database by using the gjson library or the json.Unmarshal function. The gjson library provides convenience methods to parse JSON fields, and the json.Unmarshal function requires a target type pointer to unmarshal JSON data. Both methods require preparing SQL statements and performing insert operations to persist the data into the database.

How to connect to remote database using Golang? How to connect to remote database using Golang? Jun 01, 2024 pm 08:31 PM

Through the Go standard library database/sql package, you can connect to remote databases such as MySQL, PostgreSQL or SQLite: create a connection string containing database connection information. Use the sql.Open() function to open a database connection. Perform database operations such as SQL queries and insert operations. Use defer to close the database connection to release resources.

PHP connections to different databases: MySQL, PostgreSQL, Oracle and more PHP connections to different databases: MySQL, PostgreSQL, Oracle and more Jun 01, 2024 pm 03:02 PM

PHP database connection guide: MySQL: Install the MySQLi extension and create a connection (servername, username, password, dbname). PostgreSQL: Install the PgSQL extension and create a connection (host, dbname, user, password). Oracle: Install the OracleOCI8 extension and create a connection (servername, username, password). Practical case: Obtain MySQL data, PostgreSQL query, OracleOCI8 update record.

How to handle database connections and operations using C++? How to handle database connections and operations using C++? Jun 01, 2024 pm 07:24 PM

Use the DataAccessObjects (DAO) library in C++ to connect and operate the database, including establishing database connections, executing SQL queries, inserting new records and updating existing records. The specific steps are: 1. Include necessary library statements; 2. Open the database file; 3. Create a Recordset object to execute SQL queries or manipulate data; 4. Traverse the results or update records according to specific needs.

See all articles