VirtualBox Vagrant 내에서 Mysql 서버에 연결하는 방법은 무엇입니까?
-
13-12-2019 - |
문제
Vagrant를 사용하여 새로운 VirtualBox Machine을 마운트하고 해당 VM 내에 Mysql Server를 설치했습니다.VM 외부의 해당 서버에 어떻게 연결할 수 있나요?이미 Vagrantfile의 포트 3306을 전달했지만 mysql 서버에 연결하려고 하면 다음 오류와 함께 다시 게시됩니다.'초기 통신 패킷을 읽는 중'
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0
해결책
MySQL이 127.0.0.1이 아닌 0.0.0.0에 바인딩되는지 확인하세요. 그렇지 않으면 머신 외부에서 액세스할 수 없습니다.
my.conf 파일을 편집하고 다음을 찾아 이를 확인할 수 있습니다. bind-address
항목--다음과 같이 보이기를 원합니다. bind-address = 0.0.0.0
.그런 다음 이것을 저장하고 mysql을 다시 시작하십시오.
sudo service mysql restart
프로덕션 서버에서 이 작업을 수행하는 경우 여기에 설명된 보안 영향을 알고 싶을 것입니다. https://serverfault.com/questions/257513/how-bad-is-setting-mysqls-bind-address-to-0-0-0-0
다른 팁
다음을 사용하여 상자에 로그인하십시오. ssh vagrant@127.0.0.1 -p 2222
(비밀번호 방랑자)
그 다음에: sudo nano /etc/mysql/my.cnf
#을 사용하여 다음 줄을 주석 처리합니다.
#skip-external-locking
#bind-address
저장하고 나가세요
그 다음에: sudo service mysql restart
그런 다음 SSH를 통해 MySQL 서버에 연결할 수 있습니다.
나는 최근 에이 문제를 해결했다.나는 Puphpet을 사용하여 구성을 생성했습니다.
SSH를 통해 MySQL에 연결하려면 "VAGRANT"비밀번호가 저에게 작동하지 않습니다. 대신 SSH 키 파일을 통해 인증해야했습니다.
MySQL Workbench와 연결
연결 방법
ssh
에 대한 표준 TCP / IPssh
Hostname: 127.0.0.1:2222 (forwarded SSH port)
Username: vagrant
Password: (do not use)
SSH Key File: C:\vagrantpath\puphpet\files\dot\ssh\insecure_private_key
(Locate your insercure_private_key)
.
mysql
Server Port: 3306
username: (root, or username)
password: (password)
.
연결 테스트.
MySQL Workbench 또는 Sequel Pro를 사용 하여이 작업을 수행하려고하는 사람은 다음과 같습니다.
Mysql Host: 192.168.56.101 (or ip that you choose for it)
username: root (or mysql username u created)
password: **** (your mysql password)
database: optional
port: optional (unless you chose another port, defaults to 3306)
ssh host: 192.168.56.101 (or ip that you choose for this vm, like above)
ssh user: vagrant (vagrants default username)
ssh password: vagrant (vagrants default password)
ssh port: optional (unless you chose another)
.
주어진 답변 중 어느 것도 나를 도왔으므로, 나는 이 기사.
와 간단히 답변에있는 대답은 다음과 같습니다.
MySQL Workbench를 사용하여 MySQL에 연결
Connection Method: Standard TCP/IP over SSH
SSH Hostname: <Local VM IP Address (set in PuPHPet)>
SSH Username: vagrant (the default username)
SSH Password: vagrant (the default password)
MySQL Hostname: 127.0.0.1
MySQL Server Port: 3306
Username: root
Password: <MySQL Root Password (set in PuPHPet)>
.
주어진 접근법을 사용하여 MySQL Workbench를 사용하고 Valentina Studio를 사용하여 호스트 Ubuntu 기계에서 방랑하는 MySQL 데이터베이스에 연결할 수있었습니다.
상자에 로그인 한 후에 저에게 작업 한 단계는 다음과 같습니다.
mysql 구성 파일 찾기 :
$ mysql --help | grep -A 1 "Default options"
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
.
Ubuntu 16에서는 경로가 일반적으로 /etc/mysql/mysql.conf.d/mysqld.cnf
바인딩 주소에 대한 구성 파일 변경 :
존재하는 경우 다음과 같이 값을 변경하십시오.존재하지 않으면 [mysqld] 섹션에 아무 곳이나 추가하십시오.
bind-address = 0.0.0.0
.
변경 사항을 구성 파일에 저장하고 MySQL 서비스를 다시 시작하십시오.
service mysql restart
.
데이터베이스 사용자에 대한 액세스 작성 / 부여 사용자 :
MySQL 데이터베이스에 루트 사용자로 연결하고 다음 SQL 명령을 실행하십시오.
mysql> CREATE USER 'username'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON mydb.* TO 'username'@'%';
. 이것은 나를 위해 일했습니다 : 방랑자로 MySQL에 연결
username: vagrant password: vagrant
sudo apt-get update sudo apt-get install build-essential zlib1g-dev
git-core sqlite3 libsqlite3-dev sudo aptitude install mysql-server
mysql-client
sudo nano /etc/mysql/my.cnf change: bind-address = 0.0.0.0
mysql -u root -p
use mysql GRANT ALL ON *.* to root@'33.33.33.1' IDENTIFIED BY
'jarvis'; FLUSH PRIVILEGES; exit
sudo /etc/init.d/mysql restart
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
config.vm.box = "lucid32"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
#config.vm.boot_mode = :gui
# Assign this VM to a host-only network IP, allowing you to access
it # via the IP. Host-only networks can talk to the host machine as
well as # any other machines on the same network, but cannot be
accessed (through this # network interface) by any external
networks. # config.vm.network :hostonly, "192.168.33.10"
# Assign this VM to a bridged network, allowing you to connect
directly to a # network using the host's network device. This makes
the VM appear as another # physical device on your network. #
config.vm.network :bridged
# Forward a port from the guest to the host, which allows for
outside # computers to access the VM, whereas host only networking
does not. # config.vm.forward_port 80, 8080
config.vm.forward_port 3306, 3306
config.vm.network :hostonly, "33.33.33.10"
end
.