EmmmuaCode EmmmuaCode
首页​
导航🚀​
  • 数据结构
  • 计算机网络
  • Java基础

    • JavaSE
    • JVM虚拟机
    • JUC并发编程
  • JavaWeb

    • Servlet
    • MVC
    • filter|listener
  • HTML
  • CSS
  • JavaScript
  • Vue
  • uni-app
  • Spring5
  • SpringMVC
  • SpringBoot2
  • SpringCloud
  • SpringSecurity
  • 搜索引擎

    • ElasticSearch
  • 消息队列

    • RabbitMQ
  • 服务器

    • Nginx🌐
  • 服务框架

    • Dubbo
  • Python基础
  • 数据分析
  • Hadoop
  • SQL 数据库

    • MySQL
  • NoSQL 数据库

    • NoSQL数据库概论
    • Redis
    • MongoDB
    • HBase
  • 框架

    • MyBatis
    • MyBatis-Plus
    • ShardingSphere
  • 部署

    • Linux
    • Docker
  • 管理

    • Maven
    • Git
  • 友情链接
  • 优秀博客文章
  • 索引

    • 分类
    • 标签
    • 归档
  • 其他

    • 关于
Github (opens new window)

wufan

海内存知己,天涯若比邻。
首页​
导航🚀​
  • 数据结构
  • 计算机网络
  • Java基础

    • JavaSE
    • JVM虚拟机
    • JUC并发编程
  • JavaWeb

    • Servlet
    • MVC
    • filter|listener
  • HTML
  • CSS
  • JavaScript
  • Vue
  • uni-app
  • Spring5
  • SpringMVC
  • SpringBoot2
  • SpringCloud
  • SpringSecurity
  • 搜索引擎

    • ElasticSearch
  • 消息队列

    • RabbitMQ
  • 服务器

    • Nginx🌐
  • 服务框架

    • Dubbo
  • Python基础
  • 数据分析
  • Hadoop
  • SQL 数据库

    • MySQL
  • NoSQL 数据库

    • NoSQL数据库概论
    • Redis
    • MongoDB
    • HBase
  • 框架

    • MyBatis
    • MyBatis-Plus
    • ShardingSphere
  • 部署

    • Linux
    • Docker
  • 管理

    • Maven
    • Git
  • 友情链接
  • 优秀博客文章
  • 索引

    • 分类
    • 标签
    • 归档
  • 其他

    • 关于
Github (opens new window)
  • MySQL-基础

    • MySQL-简介
    • MySQL-CRUD
    • MySQL-函数
    • MySQL 多表查询
    • MySQL 约束与自增长
    • MySQL 索引与事务
    • MySQL 表类型和存储引擎
    • MySQL 视图与管理
  • MySQL-进阶

    • MySQL 存储引擎
    • MySQL 索引
    • MySQL SQL优化
    • MySQL 视图/存储过程/触发器
    • MySQL 锁
    • MySQL InnoDB引擎
    • MySQL 管理
      • 系统数据库
      • 常用工具
        • mysql
        • mysqladmin
        • mysqlbinlog
        • mysqlshow
        • mysqldump
        • mysqlimport/source
  • MySQL-运维

    • MySQL 日志
    • MySQL 主从复制
    • MySQL 分库分表
    • MySQL 读写分离
  • NoSQL 数据库概论

    • 非关系型数据库
    • NoSQL数据库理论基础
    • NoSQL数据库分类
  • Redis

    • Redis 数据库简介
    • Redis 概述安装
    • 常用五大数据类型
    • Redis 配置文件
    • Redis 发布和订阅
    • Redis 新数据类型
    • Redis Java整合
    • Redis 事务与锁
    • Redis 持久化操作
    • Redis 主从复制
    • Redis 集群搭建
    • Redis 缓存问题
    • Redis 分布式锁
    • Redisson 的应用
    • Redis 6.0新功能
  • MongoDB

    • MongoDB 相关概念
    • MongoDB 安装
    • MongoDB 常用命令
    • MongoDB 索引-Index
    • MongoDB 整合Java案例
    • MongoDB 集群和安全
  • HBase

    • HBase简介
    • HBase系统架构
    • HBase数据定义
    • HBase数据操作
    • HBase基本原理
  • MyBatis

    • MyBatis 入门案例
    • XML 配置
    • XML 映射文件
    • 动态SQL
    • 缓存
    • MyBatis的逆向工程
    • 分页插件
  • MyBatis-Plus

    • MyBatis-Plus 简介
    • MyBatis-Plus 入门案例
    • MyBatis-Plus 基本CRUD
    • MyBatis-Plus 常用注解
    • 条件构造器和常用接口
    • MyBatis-Plus 插件
    • MyBatis-Plus 通用枚举
    • MyBatis-Plus 代码生成器
    • MyBatis-Plus 多数据源
    • MyBatisX插件
  • ShardingSphere

    • ShardingSphere_高性能架构模式
    • ShardingSphere 简介
    • ShardingSphere 主从同步
    • ShardingSphere_JDBC 读写分离
    • ShardingSphere-JDBC垂直分片
    • ShardingSphere-JDBC水平分片
    • 启动ShardingSphere-Proxy
    • ShardingSphere-Proxy读写分离
    • ShardingSphere-Proxy垂直分片
  • studynotes
  • database
  • MySQL
wufan
2022-10-04
目录

MySQL 管理

# MySQL 管理

# 系统数据库

Mysql数据库安装完成后,自带了一下四个数据库,具体作用如下:

数据库 含义
mysql 存储MySQL服务器正常运行所需要的各种信息 (时区、主从、用户、权限等)
information_schema 提供了访问数据库元数据的各种表和视图,包含数据库、表、字段类型及访问权限等
performance_schema 为MySQL服务器运行时状态提供了一个底层监控功能,主要用于收集数据库服务器性能参数
sys 包含了一系列方便 DBA 和开发人员利用 performance_schema性能数据库进行性能调优和诊断的视图

# 常用工具

# mysql

该mysql不是指mysql服务,而是指mysql的客户端工具。

语法 :
	mysql [options] [database]
选项 :
	-u, --user=name #指定用户名
	-p, --password[=name] #指定密码
	-h, --host=name #指定服务器IP或域名
	-P, --port=port #指定连接端口
	-e, --execute=name #执行SQL语句并退出
1
2
3
4
5
6
7
8

-e选项可以在Mysql客户端执行SQL语句,而不用连接到MySQL数据库再执行,对于一些批处理脚本,这种方式尤其方便。

示例:

 mysql -u root -p MySQL_Advanced -e "select * from stu";
1

image

# mysqladmin

mysqladmin 是一个执行管理操作的客户端程序。可以用它来检查服务器的配置和当前状态、创建并删除数据库等。

通过帮助文档查看选项:
	mysqladmin --help
1
2
Where command is a one or more of: (Commands may be shortened)
  create databasename   Create a new database
  debug                 Instruct server to write debug information to log
  drop databasename     Delete a database and all its tables
  extended-status       Gives an extended status message from the server
  flush-hosts           Flush all cached hosts
  flush-logs            Flush all logs
  flush-status          Clear status variables
  flush-tables          Flush all tables
  flush-threads         Flush the thread cache
  flush-privileges      Reload grant tables (same as reload)
  kill id,id,...        Kill mysql threads
  password [new-password] Change old password to new-password in current format
  ping                  Check if mysqld is alive
  processlist           Show list of active threads in server
  reload                Reload grant tables
  refresh               Flush all tables and close and open logfiles
  shutdown              Take server down
  status                Gives a short status message from the server
  start-replica         Start replication
  start-slave           Deprecated: use start-replica instead
  stop-replica          Stop replication
  stop-slave            Deprecated: use stop-replica instead
  variables             Prints variables available
  version               Get version info from server
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
语法:
	mysqladmin [options] command ...
选项:
	-u, --user=name       #指定用户名
	-p, --password[=name] #指定密码
	-h, --host=name       #指定服务器IP或域名
	-P, --port=port       #指定连接端口
1
2
3
4
5
6
7

示例:

mysqladmin -uroot –p1234 drop 'test01'
mysqladmin -u root –p 123456 version
1
2

# mysqlbinlog

由于服务器生成的二进制日志文件以二进制格式保存,所以如果想要检查这些文本的文本格式,就会使用到mysqlbinlog 日志管理工具。

语法 :
	mysqlbinlog [options] log-files1 log-files2 ...
选项 :
	-d, --database=name 指定数据库名称,只列出指定的数据库相关操作。
	-o, --offset=# 忽略掉日志中的前n行命令。
	-r,--result-file=name 将输出的文本格式日志输出到指定文件。
	-s, --short-form 显示简单格式, 省略掉一些信息。
	--start-datatime=date1 --stop-datetime=date2 指定日期间隔内的所有日志。
	--start-position=pos1 --stop-position=pos2 指定位置间隔内的所有日志。
1
2
3
4
5
6
7
8
9

示例:

A. 查看 binlog.000008这个二进制文件中的数据信息

[root@frx01 ~]# mysqlbinlog binlog.000008
# The proper term is pseudo_replica_mode, but we use this compatibility alias
# to make the statement usable on server versions 8.0.24 and older.
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
mysqlbinlog: File 'binlog.000008' not found (OS errno 2 - No such file or directory)
ERROR: Could not open log file
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
1
2
3
4
5
6
7
8
9
10
11
12
13

上述查看到的二进制日志文件数据信息量太多了,不方便查询。 我们可以加上一个参数 -s 来显示简单格式。

[root@frx01 ~]# mysqlbinlog -s binlog.000008
WARNING: --short-form is deprecated and will be removed in a future version

# The proper term is pseudo_replica_mode, but we use this compatibility alias
# to make the statement usable on server versions 8.0.24 and older.
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=1*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/;
mysqlbinlog: File 'binlog.000008' not found (OS errno 2 - No such file or directory)
ERROR: Could not open log file
SET @@SESSION.GTID_NEXT= 'AUTOMATIC' /* added by mysqlbinlog */ /*!*/;
DELIMITER ;
# End of log file
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;
/*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

# mysqlshow

mysqlshow 客户端对象查找工具,用来很快地查找存在哪些数据库、数据库中的表、表中的列或者索引。

语法 :
	mysqlshow [options] [db_name [table_name [col_name]]]
选项 :
	--count 显示数据库及表的统计信息(数据库,表 均可以不指定)
	-i 显示指定数据库或者指定表的状态信息
示例:
	#查询test库中每个表中的字段书,及行数
	mysqlshow -uroot -p2143 test --count
	#查询test库中book表的详细情况
	mysqlshow -uroot -p2143 test book --count
1
2
3
4
5
6
7
8
9
10

示例:

A. 查询每个数据库的表的数量及表中记录的数量

mysqlshow -uroot -p123456 --count

[root@frx01 ~]# mysqlshow -uroot -p123456 --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
+--------------------+--------+--------------+
|     Databases      | Tables |  Total Rows  |
+--------------------+--------+--------------+
| MySQL_Advanced     |      9 |        13582 |
| frx01              |      1 |      1000000 |
| information_schema |     79 |        31153 |
| mysql              |     37 |         3904 |
| performance_schema |    110 |       242999 |
| sys                |    101 |         5021 |
+--------------------+--------+--------------+
6 rows in set.
1
2
3
4
5
6
7
8
9
10
11
12
13

B. 查看数据库MySQL_Advanced的统计信息

mysqlshow -uroot -p123456 MySQL_Advanced --count

[root@frx01 ~]# mysqlshow -uroot -p123456 MySQL_Advanced --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: MySQL_Advanced
+-------------+----------+------------+
|   Tables    | Columns  | Total Rows |
+-------------+----------+------------+
| a           |        2 |          0 |
| employee    |        2 |          0 |
| stu         |        3 |          7 |
| stu_v_1     |        2 |         12 |
| student     |        6 |         18 |
| tb_user     |        9 |         24 |
| tb_user_pro |        3 |      13472 |
| user_logs   |        5 |         39 |
| user_v_1    |        2 |         10 |
+-------------+----------+------------+
9 rows in set.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

C. 查看数据库db01中的course表的信息

mysqlshow -uroot -p123456 MySQL_Advanced stu --count

[root@frx01 ~]# mysqlshow -uroot -p123456 MySQL_Advanced stu --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: MySQL_Advanced  Table: stu  Rows: 7
+-------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type         | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id    | int          |                    | NO   | PRI |         | auto_increment | select,insert,update,references |         |
| age   | int          |                    | NO   | MUL |         |                | select,insert,update,references |         |
| name  | varchar(255) | utf8mb4_general_ci | YES  | MUL |         |                | select,insert,update,references |         |
+-------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
1
2
3
4
5
6
7
8
9
10

D. 查看数据库db01中的course表的id字段的信息

mysqlshow -uroot -p123456 MySQL_Advanced stu id --count

[root@frx01 ~]# mysqlshow -uroot -p123456 MySQL_Advanced stu id --count
mysqlshow: [Warning] Using a password on the command line interface can be insecure.
Database: MySQL_Advanced  Table: stu  Rows: 7  Wildcard: id
+-------+------+-----------+------+-----+---------+----------------+---------------------------------+---------+
| Field | Type | Collation | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------+------+-----------+------+-----+---------+----------------+---------------------------------+---------+
| id    | int  |           | NO   | PRI |         | auto_increment | select,insert,update,references |         |
+-------+------+-----------+------+-----+---------+----------------+---------------------------------+---------+
1
2
3
4
5
6
7
8

# mysqldump

mysqldump 客户端工具用来备份数据库或在不同数据库之间进行数据迁移。备份内容包含创建表,及插入表的SQL语句。

语法 :
	mysqldump [options] db_name [tables]
	mysqldump [options] --database/-B db1 [db2 db3...]
	mysqldump [options] --all-databases/-A
连接选项 :
	-u, --user=name        指定用户名
	-p, --password[=name]  指定密码
	-h, --host=name        指定服务器ip或域名
	-P, --port=#           指定连接端口
输出选项:
	--add-drop-database    在每个数据库创建语句前加上 drop database 语句
	--add-drop-table       在每个表创建语句前加上 drop table 语句 , 默认开启 ; 不
开启 (--skip-add-drop-table)
	-n, --no-create-db     不包含数据库的创建语句
	-t, --no-create-info   不包含数据表的创建语句
	-d --no-data           不包含数据
	-T, --tab=name         自动生成两个文件:一个.sql文件,创建表结构的语句;一个.txt文件,数据文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

示例:

A. 备份db01数据库

mysqldump -uroot -p123456 frx01 > frx01.sql







 












[root@frx01 ~]# mysqldump -uroot -p123456 frx01 > frx01.sql
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@frx01 ~]# ll
总用量 597048
-rw-r--r--. 1 root root 482420224 9月   9 10:23 ABCD.tar
-rw-------. 1 root root      1697 9月   9 09:45 anaconda-ks.cfg
-rw-r--r--  1 root root  70781900 10月  4 16:31 frx01.sql
-rw-r--r--. 1 root root      1745 9月   9 09:49 initial-setup-ks.cfg
-rw-r--r--  1 root root    508543 10月  1 23:47 itcast.sql
-rw-r--r--  1 root root  57650380 9月  25 09:40 load_user_100w_sort.sql
drwxr-xr-x. 2 root root         6 9月   9 09:55 公共
drwxr-xr-x. 2 root root         6 9月   9 09:55 模板
drwxr-xr-x. 2 root root         6 9月   9 09:55 视频
drwxr-xr-x. 2 root root         6 9月   9 09:55 图片
drwxr-xr-x. 2 root root         6 9月   9 09:55 文档
drwxr-xr-x. 2 root root         6 9月   9 09:55 下载
drwxr-xr-x. 2 root root         6 9月   9 09:55 音乐
drwxr-xr-x. 2 root root         6 9月   9 09:55 桌面
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

可以直接打开db01.sql,来查看备份出来的数据到底什么样。

--
-- Table structure for table `user_logs`
--

DROP TABLE IF EXISTS `user_logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `user_logs` (
  `id` int NOT NULL AUTO_INCREMENT,
  `operation` varchar(20) NOT NULL COMMENT '操作类型, insert/update/delete',
  `operate_time` datetime NOT NULL COMMENT '操作时间',
  `operate_id` int NOT NULL COMMENT '操作的ID',
  `operate_params` varchar(500) DEFAULT NULL COMMENT '操作参数',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=utf8mb3;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `user_logs`
--
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

备份出来的数据包含:

  • 删除表的语句
  • 创建表的语句
  • 数据插入语句

如果我们在数据备份时,不需要创建表,或者不需要备份数据,只需要备份表结构,都可以通过对应的参数来实现。

B. 备份db01数据库中的表数据,不备份表结构(-t) mysqldump -uroot -p123456 -t frx01 > frx02.sql

打开 db02.sql ,来查看备份的数据,只有insert语句,没有备份表结构。

LOCK TABLES `tb_user` WRITE;
/*!40000 ALTER TABLE `tb_user` DISABLE KEYS */;
INSERT INTO `tb_user` VALUES (1,'jdTmmKQlwu1','jdTmmKQlwu','jdTmmKQlwu','2020-10-13','1'),(2,'BTJOeWjRiw2','BTJOeWjRiw','BTJOeWjRiw','202
0-06-12','2'),(3,'waQTJIIlHI3','waQTJIIlHI','waQTJIIlHI','2020-06-02','0'),(4,'XmeFHwozIo4','XmeFHwozIo','XmeFHwozIo','2020-01-11','1'),(
5,'xRrvQSHcZn5','xRrvQSHcZn','xRrvQSHcZn','2020-10-18','2'),(6,'gTDfGFNLEj6','gTDfGFNLEj','gTDfGFNLEj','2020-01-13','0'),(7,'nBETIlVCle7'
,'nBETIlVCle','nBETIlVCle','2020-09-27','1'),(8,'vmePKKZjJU8','vmePKKZjJU','vmePKKZjJU','2020-10-20','2'),(9,'pWjaLhJVaB9','pWjaLhJVaB','
pWjaLhJVaB','2020-05-07','0'),(10,'zimgGFPEQe10','zimgGFPEQe','zimgGFPEQe','2020-08-01','1'),(11,'uHpIsEALNp11','uHpIsEALNp','uHpIsEALNp'
,'2020-12-17','2'),(12,'kCfPeCgMjn12','kCfPeCgMjn','kCfPeCgMjn','2020-07-13','0'),(13,'QRkLwosIdM13','QRkLwosIdM','QRkLwosIdM','2020-08-2
4','1'),(14,'ipsKyeFeJy14','ipsKyeFeJy','ipsKyeFeJy','2020-02-22','2'),(15,'ZRrcPvYDtF15','ZRrcPvYDtF','ZRrcPvYDtF','2020-12-07','0'),(16
,'BbLUYWHeTg16','BbLUYWHeTg','BbLUYWHeTg','2020-04-17','1'),(17,'DalMVUpMnk17','DalMVUpMnk','DalMVUpMnk','2020-10-16','2'),(18,'HFtmFtnZP
i18','HFtmFtnZPi','HFtmFtnZPi','2020-11-25','0'),(19,'maHoYocalj19','maHoYocalj','maHoYocalj','2020-03-03','1'),(20,'nHKmkDGSeH20','nHKmk
DGSeH','nHKmkDGSeH','2020-01-02','2'),(21,'MZZziMtXLH21','MZZziMtXLH','MZZziMtXLH','2020-04-01','0'),(22,'bjUXRogYgF22','bjUXRogYgF','bjU
XRogYgF','2020-07-12','1'),(23,'CVgMEIwyGf23','CVgMEIwyGf','CVgMEIwyGf','2020-12-05','2'),(24,'yXVrVLgSmR24','yXVrVLgSmR','yXVrVLgSmR','2
020-04-11','0'),(25,'oaFXNzAigC25','oaFXNzAigC','oaFXNzAigC','2020-11-09','1'),(26,'IJrJiutZtD26','IJrJiutZtD','IJrJiutZtD','2020-07-17',
'2'),(27,'WGwcrfrFOB27','WGwcrfrFOB','WGwcrfrFOB','2020-09-22','0'),(28,'RbCMhegoiU28','RbCMhegoiU','RbCMhegoiU','2020-06-01','1'),(29,'R
zRzNPEsQm29','RzRzNPEsQm','RzRzNPEsQm','2020-02-24','2'),(30,'SYzgGoVRwv30','SYzgGoVRwv','SYzgGoVRwv','2020-07-03','0'),(31,'hLuUHxjJhk31
','hLuUHxjJhk','hLuUHxjJhk','2020-01-09','1'),(32,'jhUhcVaQkV32','jhUhcVaQkV','jhUhcVaQkV','2020-04-27','2'),(33,'MmbKbOrEpK33','MmbKbOrE
pK','MmbKbOrEpK','2020-05-02','0');
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

C. 将db01数据库的表的表结构与数据分开备份(-T)

mysqldump -uroot -p123456 -T /root frx01 score

执行上述指令,会出错,数据不能完成备份,原因是因为我们所指定的数据存放目录/root,MySQL认为是不安全的,需要存储在MySQL信任的目录下。那么,哪个目录才是MySQL信任的目录呢,可以查看一下系统变量 secure_file_priv 。执行结果如下:

mysql> show variables like '%secure_file_priv%';
+------------------+-----------------------+
| Variable_name    | Value                 |
+------------------+-----------------------+
| secure_file_priv | /var/lib/mysql-files/ |
+------------------+-----------------------+
1 row in set (0.01 sec)
1
2
3
4
5
6
7
mysqldump -uroot -p123456 -T /var/lib/mysql-files/ frx01 score
1





 
 

[root@frx01 ~]# mysqldump -uroot -p123456 -T /var/lib/mysql-files/ MySQL_Advanced stu
mysqldump: [Warning] Using a password on the command line interface can be insecure.
[root@frx01 ~]# cd /var/lib/mysql-files/
[root@frx01 mysql-files]# ll
总用量 8
-rw-r--r-- 1 root  root  1596 10月  4 16:48 stu.sql     #表结构文件
-rw-r----- 1 mysql mysql   68 10月  4 16:48 stu.txt     #表数据文件
1
2
3
4
5
6
7

上述的两个文件 score.sql 中记录的就是表结构文件,而 score.txt 就是表数据文件,但是需要注意表数据文件,并不是记录一条条的insert语句,而是按照一定的格式记录表结构中的数据。如下:

[root@frx01 mysql-files]# cat stu.txt
1       1       c
3       3       Java
7       7       Marry
8       8       rose
11      11      jetty
19      19      xuan
25      25      luci
1
2
3
4
5
6
7
8

# mysqlimport/source

  1. mysqlimport

mysqlimport 是客户端数据导入工具,用来导入mysqldump 加 -T 参数后导出的文本文件。

语法 :
	mysqlimport [options] db_name textfile1 [textfile2...]
示例 :
	mysqlimport -uroot -p2143 test /tmp/city.txt
1
2
3
4
[root@frx01 mysql-files]# mysqlimport -u root -p MySQL_Advanced /var/lib/mysql-files/stu.txt
Enter password:
MySQL_Advanced.stu: Records: 7  Deleted: 0  Skipped: 0  Warnings: 0
1
2
3
  1. source

如果需要导入sql文件,可以使用mysql中的source 指令 :

语法 :
	source /root/xxxxx.sql
1
2
mysql> source /var/lib/mysql-files/stu.sql
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.01 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected, 1 warning (0.14 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 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
29
30
31
32
33
34
35
36
37
38
  • 结果

image

#MySQL
上次更新: 2024/04/21, 09:42:22
MySQL InnoDB引擎
MySQL 日志

← MySQL InnoDB引擎 MySQL 日志→

最近更新
01
微信支付功能的实现与流程
11-21
02
购物车与结算区域的深入优化与功能完善
11-21
03
购物车与结算区域的功能实现与优化
11-21
更多文章>
Theme by Vdoing | Copyright © 2023-2024 EmmmuaCode | 黔ICP备2022009864号-2
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式