MySql basic instructions

1. Start MySql

/etc/init.d/mysql start

Run successfully:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.7.20-0ubuntu0.16.04.1 (Ubuntu)

Copyright (c) 2000, 2017, 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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

2. Operation

mysql -u root -p

Start successful:

[ ok ] Starting mysql (via systemctl): mysql.service.

3. Create database firstDb

mysql->create database firstDb;

4. Display the created data table

mysql->show database;


| Database           |
| information_schema |
| firstDatabase      |
| firstDb            |
| firstdb            |
| mysql              |
| performance_schema |
| sys                |
7 rows in set (0.08 sec)

5. Use the created database, that is, the later operations are based on this database

mysql->use firstDb

6. Create a table and add content. Pay attention to the use of brackets. You can input one line at a time, with a clear structure. Finally, enter the semicolon ";" press enter to complete the creation of the class table. The MySql keyword is not case sensitive.

create table class(
    -> teacher_num INT,
    -> teacher_name VARCHAR(8),
    -> student_num INT,
    -> student_name VARCHAR(20),
    -> GoodStudent TINYINT);

7. Use show tables to list all the tables in the database

mysql->show tables;
| Tables_in_firstDb |
| class             |
class is the previously created table.

8. Checklist structure

mysql> describe class;

9. Add data to the table

(1)You do not need to enter in order:
mysql> insert into class(teacher_num,teacher_name,student_num,student_name,GoodStudent)VALUES(1,'Peter',20,'finee',14);
(2)It needs to be input in sequence, that is VALUES The following values are in the same order as the fields in the table:
mysql> insert into class VALUES(1,'Peter',20,'finee',14);
(3)Enter multiple sets of data:
mysql> insert into class VALUES(1,'Peter1',20,'finee1',14)

Tags: MySQL Database Oracle Ubuntu

Posted on Tue, 05 May 2020 19:45:23 -0400 by purplehaze