【记】本地远程连接VM VirtualBox中虚拟机Centos6的数据库MySQL
目标:远程连接虚拟机中的MySQL
效果图如下
1. VBox设置好端口转发
具体步骤请看 VM VirtualBox 网络地址转换(NAT)使用详解
2. MySQL授权
如果这时我们就去远程连接MySQL数据库,会提示
必须先授权,授权方法有多种,这里只介绍其中的一种
mysql> grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.01 sec)
这时远程登录,仍然失败
C:\Users\Administrator>mysql -h 192.168.56.1 -P 33060 -u root -p Enter password: **** ERROR 2013 (HY000): Lost connection to MySQL server at 'waiting for initial communication packet', s ystem error: 0
3. 关闭防火墙
本地环境要关闭防火墙
虚拟机也要关闭防火墙
Linux关于启动和关闭防火墙的命令:
1) 重启后生效
开启: chkconfig iptables on
关闭: chkconfig iptables off
2) 即时生效,重启后失效
开启: service iptables start
关闭: service iptables stop
关闭防火墙之后,远程登录就成功了
C:\Users\Administrator>mysql -h 192.168.56.1 -P 33060 -u root -p Enter password: **** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.5.21-log Source distribution Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. 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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律