当前位置:   article > 正文

MySQL基础学习2-mysql数据导入与常用命令_mysqldump导入数据库命令

mysqldump导入数据库命令

MySQL导入数据

# 在命令行下执行
> mysqldump -u root -p az > d:\data.sql;
  • 1
  • 2

创建表

create database 数据库名;
  • 1

导出表数据

create database 数据库名;
  • 1

1. 导入数据库之前要先使用数据库

 // 用 show databases;看看有哪些数据库
 show databases;
 // 结果
 +--------------------+
| Database           |
+--------------------+
| information_schema |
| kkk                |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
 // 然后use即可
 use kkk
 
 // 可以导入了
 mysql> source D:\Mysql_data\test_data\test1\bjpowernode.sql
 
 // 查看导入的这张表的信息
 show tables;
 +---------------+
| Tables_in_kkk |
+---------------+
| dept          |
| emp           |
| salgrade      |
+---------------+
3 rows in set (0.01 sec)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28

2.查看表中的数据

select * from 表名

mysql> select * from emp;

+-------+--------+-----------+------+------------+---------+---------+--------+
| EMPNO | ENAME  | JOB       | MGR  | HIREDATE   | SAL     | COMM    | DEPTNO |
+-------+--------+-----------+------+------------+---------+---------+--------+
|  7369 | SMITH  | CLERK     | 7902 | 1980-12-17 |  800.00 |    NULL |     20 |
|  7499 | ALLEN  | SALESMAN  | 7698 | 1981-02-20 | 1600.00 |  300.00 |     30 |
|  7521 | WARD   | SALESMAN  | 7698 | 1981-02-22 | 1250.00 |  500.00 |     30 |
|  7566 | JONES  | MANAGER   | 7839 | 1981-04-02 | 2975.00 |    NULL |     20 |
|  7654 | MARTIN | SALESMAN  | 7698 | 1981-09-28 | 1250.00 | 1400.00 |     30 |
|  7698 | BLAKE  | MANAGER   | 7839 | 1981-05-01 | 2850.00 |    NULL |     30 |
|  7782 | CLARK  | MANAGER   | 7839 | 1981-06-09 | 2450.00 |    NULL |     10 |
|  7788 | SCOTT  | ANALYST   | 7566 | 1987-04-19 | 3000.00 |    NULL |     20 |
|  7839 | KING   | PRESIDENT | NULL | 1981-11-17 | 5000.00 |    NULL |     10 |
|  7844 | TURNER | SALESMAN  | 7698 | 1981-09-08 | 1500.00 |    0.00 |     30 |
|  7876 | ADAMS  | CLERK     | 7788 | 1987-05-23 | 1100.00 |    NULL |     20 |
|  7900 | JAMES  | CLERK     | 7698 | 1981-12-03 |  950.00 |    NULL |     30 |
|  7902 | FORD   | ANALYST   | 7566 | 1981-12-03 | 3000.00 |    NULL |     20 |
|  7934 | MILLER | CLERK     | 7782 | 1982-01-23 | 1300.00 |    NULL |     10 |
+-------+--------+-----------+------+------------+---------+---------+--------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

3.不看表中的数据,只看表的结构,命令:desc 表名

mysql> desc dept;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| DEPTNO | int(2)      | NO   | PRI | NULL    |       |	// 部门编号
| DNAME  | varchar(14) | YES  |     | NULL    |       | // 部门名字
| LOC    | varchar(13) | YES  |     | NULL    |       | // 地理位置
+--------+-------------+------+-----+---------+-------+

desc emp;
+----------+-------------+------+-----+---------+-------+
| Field    | Type        | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+-------+
| EMPNO    | int(4)      | NO   | PRI | NULL    |       | // 员工编号
| ENAME    | varchar(10) | YES  |     | NULL    |       | // 员工姓名
| JOB      | varchar(9)  | YES  |     | NULL    |       | // 工作岗位
| MGR      | int(4)      | YES  |     | NULL    |       | // 上级编号
| HIREDATE | date        | YES  |     | NULL    |       | // 入职日期
| SAL      | double(7,2) | YES  |     | NULL    |       | // 工资
| COMM     | double(7,2) | YES  |     | NULL    |       | // 津贴
| DEPTNO   | int(2)      | YES  |     | NULL    |       | // 部门编号
+----------+-------------+------+-----+---------+-------+

mysql> desc salgrade;
+-------+---------+------+-----+---------+-------+
| Field | Type    | Null | Key | Default | Extra |
+-------+---------+------+-----+---------+-------+
| GRADE | int(11) | YES  |     | NULL    |       | // 工资等级
| LOSAL | int(11) | YES  |     | NULL    |       | // 最低工资
| HISAL | int(11) | YES  |     | NULL    |       | // 最高工资
+-------+---------+------+-----+---------+-------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

4.MySQL常用命令

// 查看版本号
1. mysql> select version();
+------------+
| version()  |
+------------+
| 5.7.42-log |
+------------+
// 查看当前使用的是哪个数据库
2. mysql> select database();
+------------+
| database() |
+------------+
| kkk        |
+------------+
3. MySQL是不见分号不执行
写一半不想写了怎么办:\c(用来终止一条sql语句的输出入)
mysql> show
    -> databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| kkk                |
| mysql              |
| performance_schema |
| sqlfile            |
| sys                |
+--------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

5.条件查询

1. mysql> select DNAME,LOC as dd from dept;

+------------+----------+
| DNAME      | dd       |
+------------+----------+
| ACCOUNTING | NEW YORK |
| RESEARCH   | DALLAS   |
| SALES      | CHICAGO  |
| OPERATIONS | BOSTON   |
+------------+----------+
也可以把“as”省略
select DNAME,LOC dd from dept;

// 如果起的别名里有空格,用单引号(双引号也行)括起来
2. mysql> select DNAME,LOC 'd d' from dept;
+------------+----------+
| DNAME      | d d      |
+------------+----------+
| ACCOUNTING | NEW YORK |
| RESEARCH   | DALLAS   |
| SALES      | CHICAGO  |
| OPERATIONS | BOSTON   |
+------------+----------+
**3. 表达式**
mysql> select ename,sal*12 as 'double' from emp
    -> ;
+--------+----------+
| ename  | double   |
+--------+----------+
| SMITH  |  9600.00 |
| ALLEN  | 19200.00 |
| WARD   | 15000.00 |
| JONES  | 35700.00 |
| MARTIN | 15000.00 |
| BLAKE  | 34200.00 |
| CLARK  | 29400.00 |
| SCOTT  | 36000.00 |
| KING   | 60000.00 |
| TURNER | 18000.00 |
| ADAMS  | 13200.00 |
| JAMES  | 11400.00 |
| FORD   | 36000.00 |
| MILLER | 15600.00 |
+--------+----------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
条件查询(筛选)

都有哪些条件啊?

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/571243
推荐阅读
相关标签