Home IT Linux Windows Database Network Programming Server Mobile  
           
  Home \ Database \ 30 minutes with your Quick Start MySQL Tutorial     - Ubuntu install OpenMPI (Linux)

- Linux productivity tools and tips (Linux)

- Using Linux strace command trace / debug a program commonly used options (Linux)

- The traffic monitoring system: cacti (Linux)

- Through eight skills to let you become a super Linux end-user (Linux)

- BusyBox build root file system (Linux)

- Python data types summary (Programming)

- Linux initialization init systems - Systemd (Linux)

- Function Getting the Linux shell (Programming)

- Source MongoDB 3.2.1 installed on CentOS6.5 (Database)

- RedHat virtual machine to install VMware Tools (Linux)

- MySQL dual master configuration (Database)

- Linux-du and df command (Linux)

- linux remote control software (Linux)

- Ubuntu 14.04 install AMD graphics driver is fully dual monitor solution (Linux)

- Linux instructions and examples GPG encryption and decryption (Linux)

- Openfire achieve load balancing cluster by Nginx (Server)

- Learn to read the source code of vmstat (Linux)

- Python closure and function objects (Programming)

- What is Unikernel? (Linux)

 
         
  30 minutes with your Quick Start MySQL Tutorial
     
  Add Date : 2018-11-21      
         
       
         
  This is a really suitable for beginners MySQL database introductory article, even if you have never had any contact database, or that you've never heard of this thing database, be sure to believe me, I was so over that.

If you are just getting started with MySQL database, or you need to use MySQL database to store some basic data, for example, information about users, students basic information table, etc., but do not know from where to start, then this article is very suitable for you the following by an interesting case to bring you familiar with MySQL's basic instruction, I hope you can follow the operation, so after, I believe you certainly will not feel strange.

This paper tries to clear thinking and clean, though a bit long, but the text is very easy to understand, really hope can help to you!

Index of this article is as follows:

First, install the MySQL database

Installation under 1.Windows

Installation under 2.Linux

Installation under 3.MAC

Second, start using the MySQL database

0. simple to understand MySQL database

1. Enter the MySQL database at the command line

2. Check the existing database

3. Create your own database

4. Select the database to be operated

5. Create a database table in the database

6.MySQL database, database and database tables

Third, the operation of the database in a database table

1. Add data to the data table

(1) on the column name

(2) on data types

(3) about not null

(4) on primary key

2. The query data in a database table

(1) All data look-up table

(2) a specific column in the lookup table data

(3) according to specific criteria query data in the table

3. Modify the data in a database table

4. Delete the data in a database table

5. Modify the database table

(1) modify the database table columns

Column (2) delete the database table

(3) rename a database table

(4) delete the database table

6. Delete the database

Fourth, Advanced Operation

1. Modify the MySQL database login password

2. Specify the operation when the landing MySQL database database

3. Create a database table by way of documents

First, install the MySQL database

Installation under 1.Windows

Installation under 2.Linux

Installation under 3.MAC

About MySQL database installation, and here we are not given, I think the Internet Baidu about it, sure to find a lot of detailed installation steps, I am here to give out, would clearly be somewhat redundant, so I'd look for yourself I, and I believe not very difficult.

But whether it is the Windows or Linux, or is on the MAC book, the operating instructions for the MySQL database are certainly the same, so if you want to learn the basic instructions here MySQL database operations, in what platforms are not related, the following operation, for convenience, I was operating under Linux (MAC book can not afford, Windows can not afford to hurt the DOS copy operation) directly.

Second, start using the MySQL database

0. simple to understand MySQL database

Well, finally we can begin to learn the basic operation of the MySQL database, but before you start, or if you've a MySQL database does not have any idea what, you still have to know something. At this stage does not require much theoretical knowledge, you just need to know

Yes, I think you already familiar to this table, and in Excel you must have seen similar use it to store student information table, we adopted the following related operations, will be stored in a MySQL database on top of this table of contents. (Of course not the only effect of MySQL database to store such a table, and they will look after the needs of everyone.)

1. Enter the MySQL database at the command line

Our operations are performed on the command line, so to ensure you can access the command line interface (for Windows, the Start menu - Run - type cmd, to bring up the command line interface, Linux and MAC Needless to say Ha.)

The following command from the command line, you can enter the MySQL database:

xpleaf @ xpleaf-machine: ~ $ mysql -h localhost -u root -p
Enter password:
When prompted, enter the password, you can go about your password, you have the installation should be specified here is not to say, after the password is entered correctly, you should be able to see the following interface (provided that you I have been properly installed MySQL):

Welcome to the MySQL monitor Commands end with;. Or g.
Your MySQL connection id is 37
Server version: 5.5.44-0Ubuntu0.12.04.1 (Ubuntu)
  
Copyright (c) 2000, 2015, Oracle and / or its affiliates. All rights reserved.
  
Oracle is a registered trademark of Oracle Corporation and / or its
affiliates. Other names may be trademarks of their respective
owners.
  
Type 'help;' or ' h' for help Type ' c' to clear the current input statement..
  
mysql>
Therefore, according to the above operation, we enter the command to summarize the basic syntax of the MySQL database:

mysql -h hostname -u username -p

The basic explanation is as follows:

-h: followed by the host name that you want to connect to the host where the MySQL database.

-u: followed by the username, MySQL default is the root.

-p: Specifies the MySQL database using the password, if the password is empty, this parameter can be omitted.

Details are explained as follows:

We fill in the front behind the -h localhost, it represents the current host to log in to the MySQL database, in this case, -h localhost parameter and may be omitted altogether, that is, use the following command can also log in to this machine MySQL database:

mysql -u root -p

Of course, if you really want to connect to a remote host MySQL database, only you need to add -h parameter, together with the host name or IP address of the remote host can be, similar to the following:

mysql -h 202.116.96.96 -u root -p

For the -p parameter, in fact, we can add a password for the MySQL database directly behind the p, that is to say, the above operation is equivalent to the following:

mysql -u root -p123456

 Here, my password is 123456, and then, press the Enter key, you can log in directly to the MySQL database to go.

2. Check the existing database

After a successful login to the MySQL database, we first look, MySQL database, how many databases (you can understand, MySQL database is a large warehouse, then this big warehouse following a number of small warehouses, we are in these small warehouse to store our data), we performed the following operations:

mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Manager_system |
| Mysql |
| Stu_info |
| Xpleaf_server_data |
+ -------------------- +
Here you can see on my computer MySQL database saved five databases, some of which are the default, create some of my own, of course, because I had been modified before, so you might see me is not the same .

Through the above operation, we summarize view MySQL database stored in the order which several databases:

show databases;

Yes, it is that simple, but it should be noted, databases behind this word is a s, and then the final surface is a semicolon ";", and these two points are important to note, very easy to mistype.

3. Create your own database

Next, we will create a database of our own to save the data, see the following:

mysql> create database students_info;
Query OK, 1 row affected (0.01 sec)
  Here we create a database called students_info when see Query OK, 1 row affected (0.01 sec), the database was created to explain our success! To confirm this, we use the above point 2 command to check now MySQL database already exists in the database:

mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Manager_system |
| Mysql |
| Stu_info |
| Students_info |
| Xpleaf_server_data |
+ -------------------- +
  We can see that we just created the database has been successfully stored in a MySQL database!

We create a database to summarize the command syntax:

create database database name;

Is relatively simple, but it should be noted that, behind the database is no "s", but remember that after the database name is also sure to add a semicolon ";."

4. Select the database to be operated

In the above six databases, each of which is not that we need to operate, and we only need to students_info database we just created to operate on it, but if it is to operate the database, you must first tell MySQL database system, then you want to use this database to students_info related operations, how to tell the system? See the following:

mysql> use students_info;
Database changed
    When selecting a database to operate successfully, the Database changed the words will appear.

To select a database operation, the command syntax is as follows:

use database name [;]

        Then you should note that the semicolon ";" is placed in brackets [] in, say, plus without semicolons are possible, which means that you use for database use students_info choice is Yes, but in order not confusing, it is recommended to add or better it.

5. Create a database table in the database

Next we create a database table, then what is database table it? We say that is similar to the front of the student information sheet, in order to facilitate viewing, I put it down come directly
Yes, we just want to create such a table, how to create? See the following:

mysql> create table network3
    -> (
    -> Id char (10) not null primary key,
    -> Name char (16) not null,
    -> Sex char (6) not null,
    -> Age int not null,
    -> Address char (36) not null
    ->);
Query OK, 0 rows affected (0.05 sec)
    Wow! It may seem a little complicated, like a lot do not know what that means! Do not worry, the following explanation will make every one of them, of course, is to create the basic syntax of the database table:

create table database table name (column declaration);

I talk to the operation of the above basic syntax contrast, in fact, found to create a table is not difficult, complicated statements may be just the contents inside the column, and then the next one above each column is declared as a detailed description:

Column declaration statement explanation
id char (10) not null primary key to create a name for the id; char data type is a character type, the maximum length of characters is 10 characters; and the content of the column does not allow null; this column the same time as this table primary key used to distinguish between different rows in the table.
name char (16) not null create a name for the name; char data type is a character type, the maximum length of characters is 16 characters; and the contents of the column does not allow nulls.
sex char (6) not null create a name for the sex; char data type is a character type, the maximum length of the character to six characters; and the contents of the column does not allow nulls.
age int not null create a name for the age; int data type integer; and the contents of the column does not allow nulls.
address char (36) not null create a name for the sex; char data type is a character type, the maximum length of characters to 36 characters; and the contents of the column does not allow nulls.
In fact, as explained above, this table is quite detailed (if think it is quite abstract, then it is for the student according to the above information it wants to look at the table, but here we have not added any data directly to the table), but I explained again in several places.

(1) on the column name

Note that the name of each column must not be the same job.

(2) on data types

With programming languages, MySQL database has its own data types, such as the emergence of the above char, int, of course, MySQL database data types, there are many, here it is impossible to be introduced, there is a need to do more to understand, can Baidu.

(3) about not null

This parameter is non-essential, coupled with this parameter, the data show that this column must not be empty, we created the table above, we can say each column is a fundamental interest of students, so it should either be empty fishes , or may in the future there will be a case of students incomplete information, it's not OK, so here we add not null parameter. Of course, if in the future we need to add a new one, such as adding a tel column, then you might not need to specify not null parameter, because not every student has a cell phone number ah!
(4) on primary key

Consider, in the student information sheet, if many students store information, such as the table above, there may be two such students, their name, sex, age, address are the same, this is normal it! So, you have to have a data item is different, we are above the table on the specified data item id must be different is the same, which is called the primary key.

 

After this down, you can create according to their own needs a database table, but still have to pay attention to grammar problems, where a comma ",", where a semicolon ";", which must not be wrong.

After the above, we created a database table named network3 in students_info this database is created, we should just check this list to see if there is no problem:

mysql> describe network3;
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
| Id | char (10) | NO | PRI | NULL | |
| Name | char (16) | NO | | NULL | |
| Sex | char (6) | NO | | NULL | |
| Age | int (11) | NO | | NULL | |
| Address | char (36) | NO | | NULL | |
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
5 rows in set (0.00 sec)
After read carefully, we find that with the type we want to create is the same, that is no problem, of course, if you find out where there are problems, and certainly when you create where you accidentally entered the wrong, then you to delete or modify the re-created (there will be explained in detail later).

We again summarize the basic syntax of the command above, which is used to query the details of the database tables (including only the header does not contain content):

describe the database table name;

The syntax is the same with the previous, we should develop a good habit, that is, every time you create a complete database table, use this command to check to see if the database tables created with what you want is not the same .

6.MySQL database, database and database tables

Well, by the above operation, we not only learned to create a database in MySQL database, but also learned to create a database table in the new database, let's look at a simple sort out the relationship between these three bars:

        MySQL database: the equivalent of a large warehouse, there are many small warehouses;

Database: the equivalent of a large warehouse in the small warehouse, there are many small containers;

Database table: the equivalent of a small container warehouse, we are inside the stored content;

Then we can also sort out the relationship between the three by a diagram

Third, the operation of the database in a database table

 

1. Add data to the data table

After the database is created in front of the table, note that there is no data stored, let's go out into the insert data into tables:

mysql> insert into network3 values ​​( "3114006441", "xpleaf", "male", 35, "QingYuan");
Query OK, 1 row affected (0.01 sec)
The above operation, I go to add a database table data, content with the students in front of the first information table is exactly the same, here we focus to look at the data in a database table to insert command syntax:

insert into database table values ​​(value value 1, value 2 value, .......);

I created because the table is six, so there are also values ​​in the six values. This is a form to insert data in the way, of course, you can also specify to insert data into a particular column, the command syntax is as follows:

insert into database table (1 column names, column names, 2, ...) values ​​(value value 1, value value 2, ...);

That is, you can just add a table to the database part of the data, of course, the premise is that you have to comply with not null rules.

Here we add a few data for consistency of operation, we use the first method to add data:

mysql> insert into network3 values ​​( "3114006442", "Jim", "male", 38, "JiangMen");
Query OK, 1 row affected (0.00 sec)
  
mysql> insert into network3 values ​​( "3114006443", "Pei", "male", 41, "PuNing");
Query OK, 1 row affected (0.01 sec)
  
mysql> insert into network3 values ​​( "3114006440", "Xuan", "male", 36, "ShanWei");
Query OK, 1 row affected (0.02 sec)
  
mysql> insert into network3 values ​​( "3214006336", "Ting", "female", 30, "ChaoShan");
Query OK, 1 row affected (0.02 sec)
 

 

2. The query data in a database table

After to insert data into tables, then we of course want to query the data in the table. Data query table there are a number of ways (in fact, are a way), but either method, the basic command syntax is as follows:

select column names from the database table name [query condition];
The basic syntax of the command actually have, the key is to look at how to use.

(1) All data look-up table

Operation is as follows:

mysql> select * from network3;
+ ------------ + -------- + -------- + ----- + ---------- +
| Id | name | sex | age | address |
+ ------------ + -------- + -------- + ----- + ---------- +
| 3114006440 | Xuan | male | 36 | ShanWei |
| 3114006441 | xpleaf | male | 35 | QingYuan |
| 3114006442 | Jim | male | 38 | JiangMen |
| 3114006443 | Pei | male | 41 | PuNing |
| 3214006336 | Ting | female | 30 | ChaoShan |
+ ------------ + -------- + -------- + ----- + ---------- +
5 rows in set (0.00 sec)
Here, "*" is a wildcard that represents any match, if you learned the basic regular expressions, which should be better understood, and the "*" position on the column, indicating that the data is to query all columns; we query network3 this table all the data columns.

(2) a specific column in the lookup table data

Operation is as follows:

mysql> select id, name from network3;
+ ------------ + -------- +
| Id | name |
+ ------------ + -------- +
| 3114006440 | Xuan |
| 3114006441 | xpleaf |
| 3114006442 | Jim |
| 3114006443 | Pei |
| 3214006336 | Ting |
+ ------------ + -------- +
5 rows in set (0.00 sec)
Here we only query the contents of the table network3 two, and if you want to query the other columns, such as the above operation, the position of the column name with a comma "," separated from it.

(3) according to specific criteria query data in the table

Sometimes we may only want to get a person of the same sex or of data, this time we need to specify the conditions to query the basic command syntax is as follows:

select column names from the database table where the query conditions;

I see the following:

mysql> select * from network3 where name = 'xpleaf';
+ ------------ + ------ + ----- + -------- + ---------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ----- + -------- + ---------- +
| 3114006441 | xpleaf | male | 35 | QingYuan |
+ ------------ + ------ + ----- + -------- + ---------- +
1 row in set (0.02 sec)
  
mysql> select * from network3 where sex = 'female';
+ ------------ + ------ + ----- + -------- + ---------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ----- + -------- + ---------- +
| 3214006336 | Ting | female | 30 | ChaoShan |
+ ------------ + ------ + ----- + -------- + ---------- +
1 row in set (0.00 sec)
  
mysql> select * from network3 where sex = 'male' and address = 'QingYuan';
+ ------------ + ------ + ----- + -------- + ---------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ----- + -------- + ---------- +
| 3114006441 | xpleaf | male | 35 | QingYuan |
+ ------------ + ------ + ----- + -------- + ---------- +
1 row in set (0.00 sec)
  
mysql> select * from network3 where age> 40;
+ ------------ + ------ + ------ + ----- + --------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ------ + ----- + --------- +
| 3114006443 | Pei | male | 41 | PuNing |
+ ------------ + ------ + ------ + ----- + --------- +
1 row in set (0.00 sec)
  
mysql> select * from network3 where age <40 and age> = 31;
+ ------------ + ------ + ----- + -------- + ---------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ----- + -------- + ---------- +
| 3114006440 | Xuan | male | 36 | ShanWei |
| 3114006441 | xpleaf | male | 35 | QingYuan |
| 3114006442 | Jim | male | 38 | JiangMen |
+ ------------ + ------ + ----- + -------- + ---------- +
3 rows in set (0.01 sec)
  
mysql> select * from network3 where name like "% leaf";
+ ------------ + ------ + ----- + -------- + ---------- +
| Id | name | sex | age | address |
+ ------------ + ------ + ----- + -------- + ---------- +
| 3114006441 | xpleaf | male | 35 | QingYuan |
+ ------------ + ------ + ----- + -------- + ---------- +
1 row in set (0.00 sec)
  I think what the other also goes without saying, in fact, similar to certain conditions "where column name = 'value' 'in the format, followed by operation again, I believe you can easily understand, of course, if you want to know more specific details Related syntax conditions can Baidu.

 

3. Modify the data in a database table

Data can not never change, and there is always change, so sometimes we need the data in the table to make some changes, or the data is updated in the table, such as age, address, etc., you can look at the following:

Before the changes, we still look at the data in the original table:

mysql> select * from network3;
+ ------------ + -------- + -------- + ----- + ---------- +
| Id | name | sex | age | address |
+ ------------ + -------- + -------- + ----- + ---------- +
| 3114006440 | Xuan | male | 36 | ShanWei |
| 3114006441 | xpleaf | male | 35 | QingYuan |
| 3114006442 | Jim | male | 38 | JiangMen |
| 3114006443 | Pei | male | 41 | PuNing |
| 3214006336 | Ting | female | 30 | ChaoShan |
+ ------------ + -------- + -------- + ----- + ---------- +
5 rows in set (0.00 sec)
Let's start to make some modifications (updates):

# The name of "xpleaf" the address changed to "YuanTan"
mysql> update network3 set address = "YuanTan" where name = 'xpleaf';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
  
# The id is "3214006336" the name changed to "Hui"
mysql> update network3 set name = "Hui" where id = '3214006336';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
  
The # 1 all age plus
mysql> update network3 set age = age + 1;
Query OK, 5 rows affected (0.01 sec)
Rows matched: 5 Changed: 5 Warnings: 0
Let's look at the data after update table:

mysql> select * from network3;
+ ------------ + -------- + -------- + ----- + ---------- +
| Id | name | sex | age | address |
+ ------------ + -------- + -------- + ----- + ---------- +
| 3114006440 | Xuan | male | 37 | ShanWei |
| 3114006441 | xpleaf | male | 36 | YuanTan |
| 3114006442 | Jim | male | 39 | JiangMen |
| 3114006443 | Pei | male | 42 | PuNing |
| 3214006336 | Hui | female | 31 | ChaoShan |
+ ------------ + -------- + -------- + ----- + ---------- +
5 rows in set (0.00 sec)
  OK! No problem, we can see the data with the expected operation is the same, here we summarize modifications (updates) The basic syntax of the command data in the table:

update the database column names set columns = new value where possible to update the condition;

     Is relatively simple, the group is not to say it.

 

4. Delete the data in a database table

Sometimes you want to do is to delete the data in the table, rather than modifying simple, modify data in the table with a similar basic command to delete the data in the table has the following syntax:

delete from the database table where the delete condition;

Well, here we come to a row of data in the table name as "Pei" is deleted:

mysql> delete from network3 where name = 'Pei';
Query OK, 1 row affected (0.02 sec)
  Remove finished, we'll look at the data in the table:

mysql> select * from network3;
+ ------------ + -------- + -------- + ----- + ---------- +
| Id | name | sex | age | address |
+ ------------ + -------- + -------- + ----- + ---------- +
| 3114006440 | Xuan | male | 37 | ShanWei |
| 3114006441 | xpleaf | male | 36 | YuanTan |
| 3114006442 | Jim | male | 39 | JiangMen |
| 3214006336 | Hui | female | 31 | ChaoShan |
+ ------------ + -------- + -------- + ----- + ---------- +
4 rows in set (0.00 sec)
       You can see that the data has been successfully removed, if you feel delete a row is not fun then, but according to the conditions to delete multiple rows of data, of course, you can also put this table all the data to delete the table, only need to use the following command You will be able to:

delete from the database table name;

That is not to add the delete condition, but here you first do this operation, the data behind us also need to use, one thing to note is that this command only to the table all the data to delete it, and did not put this table is also deleted, the database table is still there, but this time it was an empty table, as we have just the same as when it was created.


5. Modify the database table

You might think this title to see wonder in front has not modify the contents of a database table yet? It should be noted, speaking in front of is to modify the data in a database table, attention ah, the data in the table, not the table itself, that does not involve the structure of the table itself. And speaking here, is to modify the structure of the database table, for example, add a deleted one, or simply to modify the name or type of data columns, there must be clear these are two completely different operations.

(1) modify the database table columns

Given the direct command syntax:

alter table database table column name change name of the new data type [other];

I still look at the following operations:

Before modifying, look at the details of the original database table:

mysql> describe network3;
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
| Field | Type | Null | Key | Default | Extra |
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
| Id | char (10) | NO | PRI | NULL | |
| Name | char (16) | NO | | NULL | |
| Sex | char (6) | NO | | NULL | |
| Age | int (11) | NO | | NULL | |
| Address | char (36) | NO | | NULL | |
+ --------- + ---------- + --------- + ------ + ----- + ----- - +
5 rows in set (0.00 sec)
Start making changes Action:

# Column name "adress" changed to "addr", the other remains unchanged
mysql> alter table network3 change address addr char (30) not null;
Query OK, 4 rows affected (0.04 sec)
Records: 4 Duplicates: 0 Warnings: 0
  
# Column "name" of the data type is changed to the maximum can be stored char type 20 characters, the other remains unchanged
mysql> alter table network3 change name name char (20) not null;
Query OK, 4 rows affected (0.03 sec)
Records: 4 Duplicates: 0 Warnings: 0
  
# Also modify the column "sex" in the name and data type
mysql> alter table network3 change sex Sex char (10) not null;
Query OK, 4 rows affected (0.05 sec)
Records: 4 Duplicates: 0 Warnings: 0
See details modified database tables:

mysql> describe network3;
+ ------- + ------ + ---------- + --------- + ------- + ----- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + ------ + ---------- + --------- + ------- + ----- +
| Id | char (10) | NO | PRI | NULL | |
| Name | char (20) | NO | | NULL | |
| Sex | char (10) | NO | | NULL | |
| Age | int (11) | NO | | NULL | |
| Addr | char (30) | NO | | NULL | |
+ ------- + ------ + ---------- + --------- + ------- + ----- +
5 rows in set (0.01 sec)
You can see, by the operation after modifying the format of the database table into a format we want.

Column (2) delete the database table

Sometimes, over time, some of the contents of a database table seem less important, or that have no meaning, and this time we can put a whole are removed, so that you can save some storage space a.

Delete Column basic command syntax is as follows:

alter table table name drop database column names;

We do the following operations:

mysql> alter table network3 drop addr;
Query OK, 4 rows affected (0.02 sec)
Records: 4 Duplicates: 0 Warnings: 0
We removed addr this column, although the prompt has been successfully removed, but we habitually check details after deleting a database table:

mysql> describe network3;
+ ------- + ------ + ---------- + --------- + ------- + ----- +
| Field | Type | Null | Key | Default | Extra |
+ ------- + ------ + ---------- + --------- + ------- + ----- +
| Id | char (10) | NO | PRI | NULL | |
| Name | char (20) | NO | | NULL | |
| Sex | char (10) | NO | | NULL | |
| Age | int (11) | NO | | NULL | |
+ ------- + ------ + ---------- + --------- + ------- + ----- +
4 rows in set (0.00 sec)
No problem, really delete addr this line, we then look at the data contents of the database table:

mysql> select * from network3;
+ ------------ + -------- + -------- + ----- +
| Id | name | Sex | age |
+ ------------ + -------- + -------- + ----- +
| 3114006440 | Xuan | male | 37 |
| 3114006441 | xpleaf | male | 36 |
| 3114006442 | Jim | male | 39 |
| 3214006336 | Hui | female | 31 |
+ ------------ + -------- + -------- + ----- +
4 rows in set (0.00 sec)
It erupted completely at ease, because we did the previous operation is a success!

(3) rename a database table

Through previous operations, our database table has a new look, as compared with the original structure has undergone some changes, then we'll give it to rename the database table.

Rename the table to the database of the basic command syntax is as follows:

mysql> alter table network3 rename New_network3;
Query OK, 0 rows affected (0.00 sec)
Then show tables; to look at this existing database table:

mysql> show tables;
+ ------------------------- +
| Tables_in_students_info |
+ ------------------------- +
| New_network3 |
+ ------------------------- +
1 row in set (0.00 sec)
it is good! There is no problem.

(4) delete the database table

New_network3 student information is stored in a class, they always have a graduation day, when they graduate, perhaps we no longer need to store their information, and then you can put this database table is deleted.

The basic command to delete a database table syntax is as follows:

drop table database table names;

Well, we have to operate it:

mysql> drop table New_network3;
Query OK, 0 rows affected (0.01 sec)
Then show tables; to look at the database of the database table:

mysql> show tables;
Empty set (0.00 sec)
Then you can see the display as Empty, empty, that is, at this time students_info this database has no table of the database (note, we have always been in the previous operation studnets_info use this database), normal, since the beginning we just create a database table, and then delete it again now.

 

6. Delete the database

Initially we created students_info this database in the MySQL database, in order to use it to store student information, and now we do not want to use the MySQL database to store information about a student, then you can consider students_info database deleted.

The basic command to delete the database following syntax:

drop database database name;

Although very sad, but we always have to move forward, to progress, so we have to perform the following actions:

mysql> drop database students_info;
Query OK, 0 rows affected (0.00 sec)
Then we'll use the show databases; to view the database MySQL database:

mysql> show databases;
+ -------------------- +
| Database |
+ -------------------- +
| Information_schema |
| Manager_system |
| Mysql |
| Stu_info |
| Xpleaf_server_data |
+ -------------------- +
5 rows in set (0.00 sec)
Can be found, students_info this database has not, and I know the way down to the database have some feelings, but please believe me, its mission has been completed.

Fourth, Advanced Operation

1. Modify the MySQL database login password

Anyway, your MySQL database password can not always been the same, maybe one day you are not careful it tell your friends, which in turn holds the very important data, then you have to modify the database login password.

Modify the database login password of the basic command syntax is as follows:

mysqladmin -r root -p password new password

 Note that this operation should not be operating before you log in the MySQL database.

2. Specify the operation when the landing MySQL database database

Given directly following basic command syntax:

mysql -D select to operate the database name -h hostname -u root -p

3. Create a database table by way of documents

Methods previously when we create the database tables using the command MySQL database line interface, line by line input, so that not only it is easy to make a mistake, and once entered the wrong, they have to re-enter it again, when you want to create a structure comparison when complex database tables, such an approach is clearly not in line, then we can consider the use of the file to operate.

Given directly following basic command syntax:

mysql -D select to operate the database name -h hostname -u root -p <.sql file types

You can see that in the advanced operating this part, I did not give you specific operations, it is because I feel that, following the adoption of the previous operation, if you really had the operation, you should be on the MySQL database We have a certain understanding, and this time you should be giving top priority to their own to try to do these advanced operations, when you put a few advanced operation is completed, and believe me, you operate on the MySQL database basic commands will rise a Level of! So, I am not here to give a specific operation of the matter, otherwise, meaning not too big.

Five, she said behind the words

Frankly, if you really follow the above step to do my one-step operation, the basic operation of the MySQL database should have a good grasp of the content of this article can not say that all is original, because I am also according to their own time one idea to learn to sort out this writing, also made reference to some of the information online, but here I would like to do is to provide a more complete, MySQL database entry article can follow the operation, because I have always believed, computer this thing, if only to see but not operating, there can be no improvement.

Anyway, write this one to also own a summary, and secondly, really hope to help a friend in need, think of the original own is so confused, feel the need to learn a database operation, the database should be to understand the principles of fishes Oh, if that were the case, I think I still do not understand the basic operation of MySQL.

So based on after this, I think to go to learn the principles of database like to understand more, because in your mind already have a basic idea of ​​the database, at least not so abstract, through their own operations, you have found a very specific examples to help you understand the principle of the database.

Of course, by this later, if you are just getting started programming or development, the need to use a database to store data, then this time you will not be so familiar to the database, and the corresponding need to do is call in a development language libraries to help you complete storage and reading data.
     
         
       
         
  More:      
 
- Ubuntu installed Gimp 2.6.11 (stable version) with PPA (Linux)
- Briefly explain the invasion of the four-level denial of service attack DoS Linux server (Linux)
- CentOS cross compiler core Raspberry Pi 2 (Linux)
- How to create a secure and easy to remember password (Linux)
- When Linux virtual machine to another copy of the operating system, a static IP NAT mode Invalid (Linux)
- CentOS 6.4 (64bit) install Python 2.7.5 (Linux)
- Linux Telnet access Windows 7 configuration procedure (Linux)
- Monitor log file (listener.log) (Database)
- Enterprise-class GitHub warehousing environment build (Server)
- MySQL InnoDB table --BTree basic data structures (Database)
- OpenStack / Dev stack with neutron on Ubuntu 14.04 (Server)
- How to use nmap command in Linux (Linux)
- OpenStack Folsom create an instance of the failure of the Quota Fixed_IP articles (Server)
- To control based on IP address routing policy under Linux (Linux)
- Django Signals from practice to source code analysis (Programming)
- How to modify the Emacs Major Mode Shortcuts (Linux)
- Jigsaw project will solve the problem of Java JAR hell Mody (Programming)
- Android application security of data transmission security (Programming)
- Linux see whether there is a hacker program (Linux)
- How to install MySQL on Linux Dock (Database)
     
           
     
  CopyRight 2002-2016 newfreesoft.com, All Rights Reserved.