简体   繁体   English

Docker-如何查看MySQL卷中的表?

[英]Docker - How to take a look at the Tables inside MySQL volume?

I have imported an SQL file contains my schema and all its tables, By using: 通过使用以下命令,我导入了一个包含我的架构及其所有表的SQL文件:

services:
  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
      - ./resources/file.sql:/docker-entrypoint-initdb.d/file.sql
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: db

The problem is, when I trying to retrieve data from some tables an exception in the backend appear: 问题是,当我尝试从某些表中检索数据时,后端出现异常:

throws exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'db.Configuration' doesn't exist com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'db.Configuration' doesn't exist 引发异常:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'db.Configuration'不存在com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:表'db.Configuration'不存在

And some tables work perfectly like user table. 并且有些表的工作方式与user表完全相同。

Although I have tested the SQL file in MySQL Workbench. 尽管我已经在MySQL Workbench中测试了SQL文件。

The question is, Is there a way I can see what tables are inside the db_data volume? 问题是,有什么方法可以查看db_data卷中包含哪些表?

Yes, you can see All Table information from docker command line. 是的,您可以从泊坞窗命令行查看所有表信息。

First, go inside docker container, run below command. 首先,进入docker容器,运行以下命令。

docker exec -it mysql_container_name mysql -uroot -p docker exec -it mysql_container_name mysql -uroot -p

where “ root ” is the username for MySQL database. 其中“ root ”是MySQL数据库的用户名。 After running above command it will ask you a password. 运行以上命令后,它将要求您输入密码。

Then Select Database, run below command 然后选择数据库,运行以下命令

USE Name-Of-The-Database 使用数据库名称

get the list of all tables. 获取所有表的列表。

show tables; 显示表格;

Run any query, eg select * from 运行任何查询,例如从中选择*

SELECT * FROM table_name; SELECT * FROM table_name;

I have listed down some daily docker useful commands, have a look. 我列出了一些日常的docker有用命令,看看。 https://rohanjmohite.wordpress.com/2017/08/04/docker-daily-useful-commands/ https://rohanjmohite.wordpress.com/2017/08/04/docker-daily-useful-commands/

please let me know in case any further more explanation required? 如果需要进一步说明,请告诉我?

One solution is to use MySQL Workbench and create a connection pointing to the docker database container. 一种解决方案是使用MySQL Workbench并创建一个指向docker数据库容器的连接。 From there you can check what schema tables have been created. 在这里,您可以检查已创建哪些架构表。

If the database docker container is started, you can inspect the container and find the IPAddress using the following command: 如果数据库泊坞窗容器已启动,则可以使用以下命令检查该容器并找到IPAddress:

docker inspect container-name-here 码头工人在这里检查容器名称

get the IPAddress and use it in the MySQLWorkbench to create the connection 获取IPAddress并在MySQLWorkbench中使用它来创建连接

You can execute any SQL command directly from the host to view your database. 您可以直接从主机执行任何SQL命令来查看数据库。
You are looking for this command: 您正在寻找以下命令:

docker exec -it mysql-container mysql -uroot -pmy-secret-pw -D thisdatabase -e "SELECT * FROM table_name;

where mysql-container is the name of the mysql container 其中mysql-containermysql容器的名称
where -uroot is the account for the sql container 其中-uroot是sql容器的帐户
where -pmy-secret-pw is the password for the sql container 其中-pmy-secret-pw是sql容器的密码
where thisdatabase is the name of the database to inspect 其中thisdatabase是检查数据库的名称
where table_name is obviously the database table name of interest 其中table_name显然是感兴趣的数据库表名称

TIP: if it is a new container, and you don't know the password, just run this command: 提示:如果它是一个新容器,并且您不知道密码,请运行以下命令:

sudo docker logs mysql-container 2>&1 | grep GENERATED

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM