[LINUX] Connect Vagrant's MySQL with MySQL Workbench

environment

local ・ Mac ・ MySQL Workbench ・ VagrantFile

Virtual environment ・ Vagrant ・ CentOS7 ・ MySQL

background

I wanted to operate MySQL installed on Vagrant locally with MySQL Worchbench. Try that connection. It is assumed that MySQL is already installed on Vagrant.

① Vagrantfile settings

vim Vagrantfile

Set the IP address that can connect to the virtual environment from the host OS. If you uncomment it like this, it's OK.

# Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

Then reread the settings with vagrant up or vagrant reload.

② Connect to MySQL (virtual environment)

After doing vagrant ssh, connect to MySQL in the virtual environment.

mysql -u root -p

If you have set a password in advance, enter that password (omitted) and go to the point where you can operate mysql.

Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.29 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, 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> 

③ Grant user authority with MySQL

Even if you describe the correct connection destination in Workbench, it will be played like the following, so please grant the authority of external connection. I was a little addicted here because I couldn't connect even though I was pinging ...

192.168.33.1' is not allowed to connect to this MySQL server

↑ When establishing a connection with Workbench. Type a command to grant permissions in MySQL.

mysql> GRANT ALL PRIVILEGES ON *.* TO root@'192.168.%' IDENTIFIED BY 'root password' WITH GRANT OPTION;

Now, if you can execute Query OK, 0 rows affected, 1 warning (0.00 sec), you are ready for external connection.

④ Finally

Finally, let's check if we can connect with Workbench. スクリーンショット 2020-04-18 16.27.42.png If you can confirm the connection with a test connection and confirm that you can execute the query appropriately, you are done. Thank you for your hard work.

Recommended Posts

Connect Vagrant's MySQL with MySQL Workbench
Connect to MySQL with Python within Docker
Connect to mysql
Connect to MySQL with Python on Raspberry Pi
Connect python to mysql
Use MySQL with Django
Connect to BigQuery with Python
Connect to Wikipedia with Python
Connect to Postgresql with GO
[blackbird-mysql] Monitor mysql with blackbird
Note: Differences with mysql apidriver
Connection pooling with Python + MySQL
Connect to multiple databases with SQLAlchemy
Build Mysql + Python environment with docker
Connect to Bitcoin Testnet with Pycoin
Connect to Elastic MQ with boto
Connect to MySQL using Flask SQLAlchemy
Use Unicode 6.0 emoji with django / MySQL