MySQL Database Basics Tutorial

Source: Internet
Author: User
Tags exit data structures log mysql range valid mysql database
mysql| Basic Tutorials | data | Database Database from the simple collection of initial data files to today's large-scale database management system has become an indispensable part of our daily life. Without the help of a database, many simple tasks will become tedious or even difficult to implement. In particular, large organizations such as banks, colleges and libraries rely more on database systems to achieve their normal operations. Then look on the Internet, from search engines to online shopping malls, from online chat to mailing lists, are inseparable from the database.

At present, there are a variety of database products in the market, from the solution of large enterprises to small and medium-sized enterprises or individual users of the application system, can meet the diverse needs of users. Here, we want to introduce to you the MySQL database is a number of relational database products, compared to other systems, the MySQL database can be called the fastest running SQL language database. In addition to features and options that are not available in many other databases, the MySQL database is a completely free product that allows users to download databases directly from the Web for personal or commercial use without paying any fees (recommended download site http://www.mysql.com).

Overall, the MySQL database has the following key features:

1. Unlimited number of users accessing the database at the same time;

2. Can save more than 50,000,000 records;

3. It is the database system with the fastest running speed in the current market.

4. User rights are set to be simple and effective.

Today, international companies, including Siemens and Silicon Graphics, have also started to use MySQL as their database management system, which proves the superiority of MySQL database and the prospect of broad market development.

This article will focus on some basic operations of the MySQL database, including how to establish a connection with the database, if you set up a database, and how to perform basic commands. Hope to be able to learn from the reader and master the MySQL database useful.


Entry

In general, when we visit the MySQL database, we first need to use Telnet to remotely log in the database system server, and then enter the MySQL database. The MySQL database connection commands are as follows:

Mysql-h Hostname-u Username-p[password]

Or:

Mysql-h hostname-u username--password=password

Among them, hostname is the name of the server that contains the MySQL database, username and password are the user's login name and password respectively.

If the MySQL database is installed and configured correctly, users will receive the following system feedback after entering the above command:

Welcome to the MySQL Monitor. Commands End With; or \g.

Your MySQL Connection ID is-to server Version:3.21.23-beta-log

Type ' help ' for help.

Mysql>

This allows the user to successfully enter the MySQL database system and enter commands after the mysql> command prompt. Below, we list some of the MySQL database main management commands for readers to refer to, users can also enter the help,\h after the command character or? Get a simple description of the following command.

Mysql> Help

Help (\h) displays command assistance

? (\h) Function ditto

Clear (\c) clears screen contents

Connect (\ r) Reconnect the server with the optional parameter db (database) and host (server)

Exit (\) exits the MySQL database with the same function as the QUIT command

Go (\g) sends commands to the MySQL database

Print (\p) prints the current command

Quit (\q) exit MySQL Database

Status (\s) displays server current information

Use (\u) to open the database with the database name as the command parameter

The above commands are mainly used in the MySQL database system management, if the user needs to operate on a specific database, you can access the database using the use command, the format is as follows:

mysql> use dbname;

One thing to remind readers is that the MySQL database requires the user to use ";" at the end of all commands as a command terminator.


Data types and data tables

In essence, the database is a growing complex data organization structure. In a MySQL database, the structure used to hold data records is called a datasheet. Each data record is made up of a smaller data object, or data type. Thus, in general, one or more data types form a data record, one or more data records form a data table, and one or more data tables form a database. We can interpret the above structure as the following form:

Database < Table < record < Datatype

Data types are divided into different formats and sizes, making it easy for database designers to create optimal data structures. It is necessary to introduce the concept of data type in detail before the correct selection of the appropriate data type can have an important effect on the performance of the final database.


MySQL data type

The MySQL database provides a variety of data types, some of which are more commonly used:

CHAR (M)

The char data type is used to represent a fixed-length string that can contain up to 255 characters. where m represents the length of the string.

Examples are as follows:

Car_model CHAR (10);

VARCHAR (M)

VarChar is a more flexible data type than char and is used to represent character data, but varchar can hold variable-length strings. where m represents the maximum length of the string that the data type allows to hold, as long as a string that is less than the maximum length can be saved in that data type. Therefore, it is wiser to use varchar data types for data objects that are difficult to estimate the exact length. The maximum length supported by the varchar data type is also 255 characters.

The point to note here is that although varchar is more flexible to use, the char data type is processed faster and sometimes exceeds 50% of the varchar processing speed from the overall system performance perspective. Therefore, the user should be in the design of the database should take into account all aspects of factors in order to achieve the best balance.

Examples are as follows:

Car_model VARCHAR (10);

INT (M) [Unsigned]

The int data type is used to hold any integer data from the range 2147483647 through 2147483648. If the user uses the unsigned option, the valid data range is adjusted to 0-4294967295. Examples are as follows:

Light_years INT;

By setting the data type above,-24567 is valid data, and 3000000000 is invalid because it is out of range of valid data.

Again for example:

Light_years INT unsigned;

At this point, 3 billion is valid data, and-24567 becomes invalid data.

FLOAT [(M,D)]

The float data type is used to represent floating-point data with a smaller number and provides more accurate data accuracy. where m represents the length of the floating-point data (that is, the sum of the data lengths around the decimal point), D indicates the number of numeric digits to the right of the floating-point data in the decimal point.

Examples are as follows:

Rainfall FLOAT (4,2);

According to the data type set above, 42.35 is valid data, and 324.45 and 3.542 are invalid data because they exceed the data length limit or the right digits of the decimal point are greater than the specified value 20%



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.