一、登陆mysql

命令:

mysql -uroot -p
Enter password:Welcome to the MySQL monitor.  Commands end with ; or \g.Your MySQL connection id is 8Server version: 5.7.13 MySQL Community Server (GPL)Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

#输入密码

#欢迎界面,提示:mysql命令以“;”或者“\g”结尾

#链接mysql次数(每登陆一次,id+1)

#mysql版本

#权益

#帮助说明

二、基本语法:

1、注释方式:

mysql> SELECT 1+1;     # 这个注释直到该行结束

mysql> SELECT 1+1;    -- 这个注释直到该行结束

mysql> SELECT 1 /*这是一个在行中间的注释 */ + 1;

2、获得帮助:

「1」层次帮助

mysql> ? contents      --注意:?和contents之间有一个空格。

结果如下:

mysql> ? contents

You asked for help about help category: "Contents"

For more information, type 'help <item>', where <item> is one of the following

categories:

Account Management

Administration

Compound Statements

Data Definition

Data Manipulation

Data Types

……

mysql> ? data types;     --查看支持的数据类型

结果如下:

mysql> ? data types;

You asked for help about help category: "Data Types"

For more information, type 'help <item>', where <item> is one of the following

topics:

AUTO_INCREMENT

BIGINT

BINARY

BIT

BLOB

……

mysql> ? int    --查看int类型的具体介绍

结果如下:

mysql> ? int

Name: 'INT'

Description:

INT[(M)] [UNSIGNED] [ZEROFILL]

A normal-size integer. The signed range is -2147483648 to 2147483647.

The unsigned range is 0 to 4294967295.

URL: http://dev.mysql.com/doc/refman/5.7/en/numeric-type-overview.html

练习:

查看char类型和varchar类型的说明,并分析char和varchar的存储区别。

命令如下:

mysql> ? char

Name: 'CHAR'

Description:

[NATIONAL] CHAR[(M)] [CHARACTER SET charset_name] [COLLATE

collation_name]

A fixed-length string that is always right-padded with spaces to the

specified length when stored. M represents the column length in

characters. The range of M is 0 to 255. If M is omitted, the length is

1.

*Note*:

Trailing spaces are removed when CHAR values are retrieved unless the

PAD_CHAR_TO_FULL_LENGTH SQL mode is enabled.

URL: https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html

mysql> ? varchar

Name: 'VARCHAR'

Description:

[NATIONAL] VARCHAR(M) [CHARACTER SET charset_name] [COLLATE

collation_name]

A variable-length string. M represents the maximum column length in

characters. The range of M is 0 to 65,535. The effective maximum length

of a VARCHAR is subject to the maximum row size (65,535 bytes, which is

shared among all columns) and the character set used. For example, utf8

characters can require up to three bytes per character, so a VARCHAR

column that uses the utf8 character set can be declared to be a maximum

of 21,844 characters. See

https://dev.mysql.com/doc/refman/8.0/en/column-count-limit.html.

MySQL stores VARCHAR values as a 1-byte or 2-byte length prefix plus

data. The length prefix indicates the number of bytes in the value. A

VARCHAR column uses one length byte if values require no more than 255

bytes, two length bytes if values may require more than 255 bytes.

*Note*:

MySQL follows the standard SQL specification, and does not remove

trailing spaces from VARCHAR values.

VARCHAR is shorthand for CHARACTER VARYING. NATIONAL VARCHAR is the

standard SQL way to define that a VARCHAR column should use some

predefined character set. MySQL uses utf8 as this predefined character

set. https://dev.mysql.com/doc/refman/8.0/en/charset-national.html.

NVARCHAR is shorthand for NATIONAL VARCHAR.

URL: https://dev.mysql.com/doc/refman/8.0/en/string-type-syntax.html

区别如下:

在MySQL中,char和varchar都是用来存储字符串的,区别在于char有固定的长度,而varchar属于可变长的字符类型。

「2」快速查阅帮助

实际使用中,可以通过使用关键字进行快速查询。

执行如下命令:

mysql> ? show

mysql> ? create database;

请写出create databases命令的语法:

三、熟悉系统数据库

1、显示系统数据库

mysql> show databases;

显示结果如下(写出系统数据库名字):

2、选择mysql数据库

mysql> use mysql;

3、显示mysql数据库中所有表格

mysql> show tables;

mysqls数据库中有多少张表格?

mysql数据库里有37张不同的表格,通过show tables命令查看当前数据库中的表格

4、查看user表结构

mysql> desc user;

user表格有多少个字段?

有6个字段

5、通过user表查看系统的用户信息

mysql>select user from user;

user表中登记了多少个用户?请写出所有用户名。

6、执行如下命令,写出结果并解释其功能:

mysql> select host,user,password_last_changed from user;

结果:

功能:

7、使用命令查看db表中所有用户(user)的查询权限(select_priv)。

命令:

四、创建数据库

创建数据库语法:create database dbname;

1、使用命令创建数据库jxgl

命令如下:

2、在jxgl数据库中创建如下表格:

Student表结构

字段名称

数据类型

长度

精度

小数位数

是否允许Null值

说明

Sno

Char

10

0

0

学号,主码

Sname

Varchar

8

0

0

姓名

Ssex

Char

2

0

0

性别,取值:男或女

Sbirthday

Date

8

0

0

出生日期

Sdept

Char

16

0

0

系名

Speciality

Varchar

20

0

0

专业名

创建student表命令如下:

(2)Course表(课程名称表)的表结构

字段名称

数据类型

长度

精度

小数位数

是否允许Null值

说明

Cno

Char

5

0

0

课程号,主码

Cname

Varchar

20

0

0

课程名

创建Course表命令如下:

(3)SC表(成绩表)的表结构

字段名称

数据类型

长度

精度

小数位数

是否允许Null值

说明

Sno

Char

10

0

0

学号,外码

Cno

Char

5

0

0

课程号,外码

Degree

Decimal

5

5

1

成绩,0~100之间

创建SC表命令如下:

3、使用show命令显示jxgl数据库中所有的表格。

命令如下:

4、使用desc命令显示student表结构:

命令如下:

结果如下:

五、数据导入导出

1、将jxgl数据库中数据导出sql文档

输入的命令行:

cd ~/Desktop

mysqldump -u root -p jxgl> jxgl.sql  

输入后会让你输入进入MySQL的密码,如果导出单张表的话在数据库名后面输入表名即可。

2、导入jxgl数据库

(1)登陆mysql服务器

mysql –uroot –p --登陆mysql服务器

mysql>create database jxgl; --创建jxgl数据库

mysql> source jxgl.sql --执行source命令(执行jxgl.sql中的sql代码)

【数据库】MySQL基本操作(基操~)相关推荐

  1. 数据库MySQL系统实操实验从安装系统到实际操作全过程,五万字系列五,这不直接学完去学校装杯?

    系列链接: MySQL的安装及数据库的创建和维护 实验二:数据表的创建与修改管理 实验三:表数据的查询操作 实验四:数据插入.修改.删除操作 实验五:视图的创建与管理 实验六:MySQL的用户与权限( ...

  2. JAVA萌新学习day17.18天 数据库MySQL

    JAVA萌新学习day17.18天 数据库MySQL基本操作 MySQLDemo // name age address 小明 18 大连 小明 18 大连 小明 18 大连/*** 1.数据库 -& ...

  3. linux mysql常用基本操作,Linux下MySQL数据库常用基本操作 一

    Linux下MySQL数据库常用基本操作 一 0.登录数据库 mysql -u root -p 1.显示数据库 show databases; 2.选择数据库 use 数据库名; 3.显示数据库中的表 ...

  4. Qt实战案例(28)——利用QSQL相关类实现对MySQL数据库的基本操作及相关设置详解

    目录 一.项目介绍 二.项目基本配置 2.1 安装MySQL 2.2 创建Qt项目 2.3 移动libmysql.dll文件 三.UI界面设计 四.主程序实现 4.1 pro文件 4.2 main.c ...

  5. mysql数据库读写操作_一看就会,MySQL数据库的基本操作(二)

    上一节学习了MySQL数据库的基本操作的几个命令,1.登陆数据库:mysql -h localhost -u root -p.2.查看已有的数据库命令:show databases. 3.创建自己的数 ...

  6. mysql 四大基础操作_mysql数据库的基本操作

    mysql数据库的基本操作 首先我们要把mysql装好 mkdir chen/ mount.cifs //192.168.100.23/LNMP chen/ [root@localhost ~]# y ...

  7. mysql 修改库的校对集_mysql数据库的基本操作(增删改查、字符集、校对集)

    MySQL数据库概述 MySQL数据库是经典的关系型数据库管理系统,MySQL 是最流行的关系型数据库管理系统之一,在 WEB 应用方面,MySQL是最好的 RDBMS (Relational Dat ...

  8. 第六天 02.mysql数据库的基本操作和密码爆破

    mysql数据库的基本操作 简介: ​ 数据库是什么 ​ 存储数据的仓库,数据是有组织的进行存储. mysql是一种关系数据库管理系统 使用工具:phpstudy mysql 默认端口 3306 一. ...

  9. MySQL 数据库的基本操作

      其实各种SQL数据库的基本操作都是基本相似的,此处主要写MySQL,在安装好MySQL以后,要创建数据库,这是使用数据MySQL各种功能的前提,主要内容包括:创建数据库.删除数据库.不同类型的数据 ...

最新文章

  1. DEV开发之控件NavBarControl
  2. rfc8222045
  3. Oracle 本地验证和密码文件
  4. windows 全局变量_如何在Windows中使用全局系统环境变量
  5. cups支持的打印机列表_Win10“Microsoft Print to PDF”虚拟打印机不见了,如何找回?...
  6. CCF 201609-2 火车购票
  7. Linux 安装Zookeeper
  8. win10怎么打开计算机树形,win10系统中显示树形目录文件夹的两种方法
  9. oppo怎么修改dns服务器地址,OPPO R7/R7 Plus修改DNS图文教程
  10. 内网ip和外网ip区别
  11. office表格怎么冻结前两行_冻结Excel表格中多行或多列的方法
  12. Ubuntu 18.04 究极美化教程
  13. Linux 添加802.11n网卡驱动
  14. oracle12c生命周期,Oracle 12c 新特性之: ILM 数据生命周期管理
  15. 山西大同大学计算机分数线,山西大同大学录取分数线2021是多少分(附历年录取分数线)...
  16. win10触摸键盘TabTip软件特性
  17. Ubuntu下tar命令使用详解 .tar解压、.tar压缩
  18. Android6.0运行时权限(危险权限列表)
  19. 脚本之win系统下批量ping通网段
  20. 语料库数据处理个案实例(计算机搭配强度、删除表中的停用词、词料检索的KWIC实现)

热门文章

  1. 公示!首批8款产品方案入围2023年度智驾竞争力评选
  2. Python调用有道翻译API
  3. windows自带局域网扫描IP
  4. AB实验原理及案例实例(python代码实现)
  5. 【Java基础】--05.java基本类型与包装类型
  6. windows双路由怎么配置
  7. [C5W2] Sequence Models - Natural Language Processing and Word Embeddings
  8. MySQL数据库使用——MySQL数据库管理
  9. 【MATLAB】如何使用matlab截图并保存?
  10. SkyWalking客户端的使用