1. 程式人生 > 資料庫 >mysql-8.0.18基礎操作快速入門

mysql-8.0.18基礎操作快速入門

mysql-8.0基礎操作快速入門

1 mysql下載與安裝使用

    前往mysql官網下載對應版本,我選擇的版本是mysql-8.0.18-winx64
    將下載到的壓縮包解壓,然後在cmd視窗進入內部bin目錄,使用如下命令啟動mysql後臺服務

D:\mysql-8.0.18-winx64\bin>mysqld

    新開cmd視窗,進入內部bin目錄,使用如下命令

D:\mysql-8.0.18-winx64\bin>mysql -u root -p
Enter password: **********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.18 MySQL Community Server - GPL

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

成功進入mysql互動模式。

2 mysql基礎命令

mysql> show databases;//顯示所有的資料庫
+--------------------+
| Database           |
+--------------------+
| bj18               |
| db111              |
| information_schema |
| mysql              |
| mytest             |
| performance_schema |
| sys                |
| webby              |
+--------------------+
8 rows in set (0.03 sec)

mysql> create database mydatabase;//建立一個數據庫,命名為mydatabase
Query OK,1 row affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| bj18               |
| db111              |
| information_schema |
| mydatabase         |
| mysql              |
| mytest             |
| performance_schema |
| sys                |
| webby              |
+--------------------+
9 rows in set (0.00 sec)

mysql> drop database mydatabase;//刪除指定資料庫
Query OK,0 rows affected (0.02 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| bj18               |
| db111              |
| information_schema |
| mysql              |
| mytest             |
| performance_schema |
| sys                |
| webby              |
+--------------------+
8 rows in set (0.00 sec)

mysql> use mydatabase;//開啟mydatabase資料庫
					//mydatabase資料庫重新建立
Database changed
//建立資料表,並指定幾個域
mysql> create table student(
    -> id int(4) not null primary key auto_increment,-> name char(20) not null,-> sex int(4) not null default '0',-> degree double(16,2));
Query OK,0 rows affected,3 warnings (0.06 sec)

mysql> show tables;//檢視mydatabase資料庫中的所有表
+----------------------+
| Tables_in_mydatabase |
+----------------------+
| student              |
+----------------------+
1 row in set (0.01 sec)

mysql> desc student;//檢視指定表的結構
+--------+--------------+------+-----+---------+----------------+
| Field  | Type         | Null | Key | Default | Extra          |
+--------+--------------+------+-----+---------+----------------+
| id     | int(4)       | NO   | PRI | NULL    | auto_increment |
| name   | char(20)     | NO   |     | NULL    |                |
| sex    | int(4)       | NO   |     | 0       |                |
| degree | double(16,2) | YES  |     | NULL    |                |
+--------+--------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)

//在表中插入記錄
mysql> insert into student values(1,'joan',89.2);
Query OK,1 row affected (0.01 sec)

//查詢表中的記錄
mysql> select id,name,sex,degree from student;
+----+------+-----+--------+
| id | name | sex | degree |
+----+------+-----+--------+
|  1 | joan |   0 |  89.20 |
+----+------+-----+--------+
1 row in set (0.00 sec)

//刪除指定表
mysql> drop table student;
Query OK,0 rows affected (0.02 sec)

mysql> show tables;
Empty set (0.00 sec)

mysql>

這只是最基本的命令,比如select還有很多種用法,並沒有一一列舉出來emmmmm