Detailed explanation of MySQL database (based on Ubuntu 14.0.4 LTS 64 bit)

Detailed explanation of MySQL database (based on Ubuntu 14.0.4 LTS 64 bit)

1. Composition and related concepts of MySQL database

First of all, you need to understand that MySQL is a relational database. The biggest difference between it and a non-relational database is the concept of tables.

+The entire MySQL environment can be understood as a single largest database: A

+Database B created with mysql belongs to A and is a data warehouse, equivalent to a folder in the system

+Data table C: is the specific place to store data, equivalent to the file in the system. A database B contains several data tables C (note that database B and A here are different)

+Record D: A row in a data table is called a record. Therefore, when we create a data table, we must create an id column to identify "which record this is". The value of the id column cannot be the same and must be unique, just like an ID number. There can be multiple records in a table C.

+Field E: Each column in a table is called a "field". Each field in the database has regulations, such as: field data type, empty or not empty judgment, automatic growth, etc. A record D can have multiple fields E.

+Data F: The intersection of rows and columns is the real "data" F.

2. Basic database operations (under Ubuntu environment) and common command examples.

2.1 Log in to mysql: mysql-uroot-pu: log in with username, -p: enter password

2.2 View the database: After entering the above command, you will be asked to enter the password. After successful login, the interface shown above will be displayed to view the data B that comes with system A

showdatabases; Note that the semicolon must be included. The following figure shows the system's built-in database.

2.3 Create a database: create database mytest; this creates a database B named mytest.

2.4 Among the above 4 databases, how do we choose the database we want? usemytest, so our database mytest is selected.

2.5 If you want to delete the database: dropdatabasemytest. This will delete the database without any reminder.

2.6 Check the current status: status;

2.7 Display table C in the current database in the following two ways. a:showtables;b:showtablesFROMmytest;.Mytest is the database we created.

2.8 Creating and Deleting Data Tables

createtablemytable(idint,nameint);

droptablemytable;

2.9 How to use the established data table, that is, how to insert data into the data table? insertintomytable(id,name)values(1,10);

2.10 Query the data in the table, selectid,namefrommytablewhereid=1order; or select*frommytable

2.11 Update the data in the table, update mytable set name=20 where id=1;

2.12 Deleting a table: deletefrommytable; or droptablemytable;

2.13 Modification of table structure

(1) Add a field format:

altertabletable_nameaddcolumn(field name field type);—This method has brackets

(2) Specify the location where the field is inserted:

altertabletable_nameaddcolumnfield namefield typeafter a field;

(3) Modify field name/type

altertabletable_namechange old field name new field name new field type;

(4) Change the name of the table

altertabletable_namerenametonew_table_name;

(5) Clear all data in the table at one time

truncatetabletable_name; This method will also make the ID in the table start from 1

(6) Delete a field:

altertabletable_namedrop field name;

2.14 Change password format: mysqladmin -u username -p old password password new password;

2.15 Display the structure of the table: describemytables;

2.16 Display the current database and user show database(); show user();

3 Note:

3.1 If you forget to add a semicolon after pressing Enter when typing a command, you do not need to retype the command, just type a semicolon and press Enter.

3.2 You can use the cursor up and down keys to call up previous commands.

Summarize

The above is all the content of this article about the detailed explanation of MySQL database (based on Ubuntu 14.0.4 LTS 64-bit). I hope it will be helpful to everyone. Interested friends can refer to other related topics on this site. If there are any deficiencies, please leave a message to point them out. Thank you friends for supporting this site!

You may also be interested in:
  • Detailed explanation of three ways to start/stop/restart MySQL database in Ubuntu Server
  • How to connect Python to MySQL database under Ubuntu system
  • Perfectly implement MySQL database migration under Ubuntu
  • MySql database backup script code under Ubuntu Server
  • How to cancel the local binding restriction of MySQL database in Ubuntu
  • How to share MySQL database between Ubuntu and Windows
  • How to use Qt to connect to MySQL database under ubuntu linux

<<:  How to set a fixed IP in Linux (tested and effective)

>>:  Comparing Node.js and Deno

Recommend

Solution to the horizontal scroll bar in iframe under IE6

The situation is as follows: (PS: The red box repr...

Use of align-content in flex layout line break space

1. The effect diagram implemented in this article...

How to use node to implement static file caching

Table of contents cache Cache location classifica...

JavaScript adds event listeners to event delegation in batches. Detailed process

1. What is event delegation? Event delegation: Ut...

In-depth understanding of the life cycle comparison between Vue2 and Vue3

Table of contents Cycle comparison usage Summariz...

JavaScript super detailed implementation of web page carousel

Table of contents Creating HTML Pages Implement t...

React Native scaffolding basic usage detailed explanation

Build the project Execute the command line in the...

Use nginx + secondary domain name + https support

Step 1: Add a secondary domain name to the Alibab...

Detailed explanation of the use of Teleport in Vue3

Table of contents Purpose of Teleport How Telepor...

JavaScript object built-in objects, value types and reference types explained

Table of contents Object Object Definition Iterat...

How to insert Emoji expressions into MySQL

Preface Today, when I was designing a feedback fo...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Usage and description of HTML tag tbody

The tbody element should be used in conjunction wi...

Generate OpenSSL certificates in Linux environment

1. Environment: CentOS7, Openssl1.1.1k. 2. Concep...