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',0,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

mysql-8.0.18基础操作快速入门mysql-8.0.18基础操作快速入门 一月换一次名字的秃头少年 发布了2 篇原创文章 · 获赞 0 · 访问量 221 私信 关注
上一篇:mysql备份和还原


下一篇:MYSQL常用指令