MySql基本使用指令
阿新 • • 發佈:2019-01-23
1.啟動MySql
/etc/init.d/mysql start
執行成功顯示:
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
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2.執行
mysql -u root -p
啟動成功:
[ ok ] Starting mysql (via systemctl): mysql.service.
3.建立資料庫firstDb
mysql->create database firstDb;
4.顯示已建立的資料表
mysql->show database;
顯示:
+--------------------+
| Database |
+--------------------+
| information_schema |
| firstDatabase |
| firstDb |
| firstdb |
| mysql |
| performance_schema |
| sys |
+--------------------+
7 rows in set (0.08 sec)
5.使用建立的資料庫,也就是後面的操作是基於這個資料庫
mysql->use firstDb
6.建立一個表並新增內容,注意使用的是括號,可以一行一行輸入,結構比較清楚,最後再輸入分號“;”按回車,即可完成class表的建立。MySql關鍵字不區分大小寫。
create table class(
-> teacher_num INT,
-> teacher_name VARCHAR(8),
-> student_num INT,
-> student_name VARCHAR(20),
-> GoodStudent TINYINT);
7.用show tables 列出資料庫所有的的表
mysql->show tables;
+-------------------+
| Tables_in_firstDb |
+-------------------+
| class |
+-------------------+
class即為之前建立的表。
8.檢查表結構
mysql> describe class;
9.向表中新增資料
(1)不需要按順序輸入:
mysql> insert into class(teacher_num,teacher_name,student_num,student_name,GoodStudent)VALUES(1,'Peter',20,'finee',14);
(2)需要按順序輸入也就是VALUES後的值與表中欄位的順序是一致的:
mysql> insert into class VALUES(1,'Peter',20,'finee',14);
(3)輸入多組資料:
mysql> insert into class VALUES(1,'Peter1',20,'finee1',14),
VALUES(1,'Peter2',20,'finee2',14),
VALUES(1,'Peter3',20,'finee3',14);