Home >Database >Mysql Tutorial >How to use Docker to build mysql that can be accessed externally

How to use Docker to build mysql that can be accessed externally

WBOY
WBOYforward
2023-05-27 09:49:352102browse

Install mysql 8.0

docker run -p 63306:3306 -e mysql_root_password=zhaooleemysql --name zhaooleemysqldb -d mysql:8.0
  • p 53306:3306 Map the 3306 port of the docker container to the 63306 port of the host

  • -e mysql_root_password=zhaooleemysql The root user login password is zhaooleemysql

  • --name zhaooleemysqldb The name of the new container is zhaooleemysqldb

  • mysql :8.0 The mysql database version used is 8.0

Enter the container

docker exec -it zhaooleemysqldb bash

How to use Docker to build mysql that can be accessed externally

Log in to the database

mysql -uroot -p
zhaooleemysql

Create a new user (8.0 is more strict, it is more troublesome to log in remotely with the root user, we choose to create a new user)

create user 'zhaoolee' identified with mysql_native_password by 'eelooahzpw';

zhaoolee The new user name is zhaoolee mysql_native_password The password encryption method is mysql_native_password eelooahzpw The password for the new user is eelooahzpw

Add permissions for the new user zhaoolee

grant all privileges on *.* to 'zhaoolee';

Refresh permissions

flush privileges;

How to use Docker to build mysql that can be accessed externally

New database

create database v2fy charset=utf8;

The name of the new database is v2fy

Exit the database

exit

Exit the docker container

control + p + q

How to use Docker to build mysql that can be accessed externally

Try to connect with navicat

How to use Docker to build mysql that can be accessed externally

How to use Docker to build mysql that can be accessed externally

The above is the detailed content of How to use Docker to build mysql that can be accessed externally. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete