进入docker容器内部操作mysql数据库

文章目录

1、查询docker容器

bash 复制代码
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                       COMMAND                   CREATED        STATUS      PORTS                                                                                  NAMES
098f11933a88   bitnami/kafka               "/opt/bitnami/script..."   2 weeks ago    Up 8 days   9092/tcp, 0.0.0.0:9097->9097/tcp, :::9097->9097/tcp                                    kafka-03
a250cf273334   bitnami/kafka               "/opt/bitnami/script..."   2 weeks ago    Up 8 days   9092/tcp, 0.0.0.0:9096->9096/tcp, :::9096->9096/tcp                                    kafka-02
65ce0954dcbc   bitnami/kafka               "/opt/bitnami/script..."   2 weeks ago    Up 8 days   9092/tcp, 0.0.0.0:9095->9095/tcp, :::9095->9095/tcp                                    kafka-01
7027dccb277a   bitnami/zookeeper           "/opt/bitnami/script..."   2 weeks ago    Up 8 days   2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp                kafka-zk
a7b2efed4e65   nickzurich/efak:latest      "entrypoint.sh"           3 weeks ago    Up 8 days   0.0.0.0:8048->8048/tcp, :::8048->8048/tcp, 8080/tcp                                    kafka-eagle
1739859499c5   nginx                       "/docker-entrypoint...."   3 months ago   Up 8 days   0.0.0.0:80->80/tcp, :::80->80/tcp                                                      sc-nginx
59ae3d865576   nacos/nacos-server:v2.2.2   "bin/docker-startup...."   3 months ago   Up 8 days   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848->9848/tcp, :::9848->9848/tcp   spzx-nacos
2732056a547f   quay.io/minio/minio         "/usr/bin/docker-ent..."   5 months ago   Up 8 days   0.0.0.0:9000-9001->9000-9001/tcp, :::9000-9001->9000-9001/tcp                          spzx-minio
c14772057ab8   redis                       "docker-entrypoint.s..."   5 months ago   Up 8 days   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                              spzx-redis
ab66508d9441   mysql:8                     "docker-entrypoint.s..."   5 months ago   Up 8 days   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                   spzx-mysql
[root@localhost ~]# 

2、进入mysql容器内部

bash 复制代码
[root@localhost ~]# docker exec -it spzx-mysql /bin/bash
root@ab66508d9441:/# 

3、连接mysql数据库

bash 复制代码
[root@localhost ~]# docker exec -it spzx-mysql /bin/bash
root@ab66508d9441:/# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 544
Server version: 8.0.27 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

4、查询mysql所有的数据库

bash 复制代码
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| db_spzx            |
| information_schema |
| mysql              |
| performance_schema |
| spzx-cloud-order   |
| spzx-cloud-user    |
| sys                |
| tingshu_account    |
| tingshu_album      |
| tingshu_dispatch   |
| tingshu_live       |
| tingshu_order      |
| tingshu_payment    |
| tingshu_system     |
| tingshu_user       |
+--------------------+
15 rows in set (0.19 sec)

mysql> 

5、使用某个数据库

bash 复制代码
mysql> use db_spzx;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> 

6、展示数据库中所有的表

bash 复制代码
mysql> show tables;
+---------------------+
| Tables_in_db_spzx   |
+---------------------+
| brand               |
| category            |
| category_brand      |
| coupon_info         |
| coupon_range        |
| coupon_user         |
| order_info          |
| order_item          |
| order_log           |
| order_statistics    |
| payment_info        |
| product             |
| product_details     |
| product_sku         |
| product_spec        |
| product_unit        |
| region              |
| sys_login_log       |
| sys_menu            |
| sys_oper_log        |
| sys_role            |
| sys_role_menu       |
| sys_user            |
| sys_user_role       |
| user_address        |
| user_browse_history |
| user_collect        |
| user_info           |
+---------------------+
28 rows in set (0.04 sec)

mysql> 

7、查询某张表

bash 复制代码
mysql> select * from brand;
+----+-------+---------------------------------------------------------------------------------------+---------------------+---------------------+------------+
| id | name  | logo                                                                                  | create_time         | update_time         | is_deleted |
+----+-------+---------------------------------------------------------------------------------------+---------------------+---------------------+------------+
|  1 | ??    | http://139.198.127.41:9000/sph/20230506/??.png                                        | 2023-05-06 09:30:27 | 2023-05-06 09:30:27 |          0 |
|  2 | ??    | http://139.198.127.41:9000/sph/20230506/??.png                                        | 2023-05-06 09:31:19 | 2023-06-04 08:37:16 |          0 |
|  6 | OPPO2 | http://192.168.136.142:9001/spzx-bucket/20230525/f550ff4584be42eabf047ccbee062230.jpg | 2023-05-25 01:41:12 | 2023-05-25 02:17:08 |          1 |
|  7 | OPPO2 | http://192.168.136.142:9001/spzx-bucket/20230525/803c8a6427134d06a12570eadab5d5d2.jpg | 2023-05-25 02:17:46 | 2023-05-25 02:18:12 |          1 |
|  8 | ??    | http://192.168.136.142:9001/spzx-bucket/20230601/e3f92d0132964809bac91ce0bb5985e9.jpg | 2023-06-01 05:06:15 | 2023-06-04 03:35:43 |          1 |
|  9 | ??    | http://192.168.136.142:9001/spzx-bucket/20230604/6abcd8dbb83b4d8e8326394a7bb28757.jpg | 2023-06-04 03:35:54 | 2023-06-04 08:27:18 |          1 |
| 10 | ??2   | http://192.168.136.142:9001/spzx-bucket/20230604/5e10ed9390a6478db564f16f5105d253.jpg | 2023-06-04 08:27:30 | 2023-06-04 08:29:22 |          1 |
| 11 | ??    | http://192.168.74.133:9000/spzx-bucket/brandLogo/2024-03/16/1710558937775_e0a4e0.jpg  | 2024-03-06 11:57:15 | 2024-03-16 03:15:38 |          0 |
| 12 | ???   | http://192.168.74.133:9000/spzx-bucket/brandLogo/2024-03/14/1710407326870_406bc0.png  | 2024-03-14 09:08:48 | 2024-03-14 09:08:48 |          0 |
+----+-------+---------------------------------------------------------------------------------------+---------------------+---------------------+------------+
9 rows in set (0.00 sec)

mysql> 

8、断开mysql

bash 复制代码
mysql> exit
Bye
root@ab66508d9441:/# 

9、退出mysql容器

bash 复制代码
mysql> exit
Bye
root@ab66508d9441:/# exit
exit
[root@localhost ~]# 
相关推荐
桀桀桀桀桀桀3 分钟前
数据库中的用户管理和权限管理
数据库·mysql
superman超哥1 小时前
04 深入 Oracle 并发世界:MVCC、锁、闩锁、事务隔离与并发性能优化的探索
数据库·oracle·性能优化·dba
用户8007165452001 小时前
HTAP数据库国产化改造技术可行性方案分析
数据库
engchina2 小时前
Neo4j 和 Python 初学者指南:如何使用可选关系匹配优化 Cypher 查询
数据库·python·neo4j
engchina2 小时前
使用 Cypher 查询语言在 Neo4j 中查找最短路径
数据库·neo4j
尘浮生2 小时前
Java项目实战II基于Spring Boot的光影视频平台(开发文档+数据库+源码)
java·开发语言·数据库·spring boot·后端·maven·intellij-idea
威哥爱编程2 小时前
SQL Server 数据太多如何优化
数据库·sql·sqlserver
小华同学ai2 小时前
AJ-Report:一款开源且非常强大的数据可视化大屏和报表工具
数据库·信息可视化·开源
Acrelhuang2 小时前
安科瑞5G基站直流叠光监控系统-安科瑞黄安南
大数据·数据库·数据仓库·物联网
川石课堂软件测试3 小时前
性能测试|docker容器下搭建JMeter+Grafana+Influxdb监控可视化平台
运维·javascript·深度学习·jmeter·docker·容器·grafana