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
Release: 2023-05-27 09:49:35
forward
2141 people have browsed it

Install mysql 8.0

docker run -p 63306:3306 -e mysql_root_password=zhaooleemysql --name zhaooleemysqldb -d mysql:8.0
Copy after login
  • 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
Copy after login

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

Log in to the database

mysql -uroot -p
zhaooleemysql
Copy after login

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';
Copy after login

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';
Copy after login

Refresh permissions

flush privileges;
Copy after login

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

New database

create database v2fy charset=utf8;
Copy after login

The name of the new database is v2fy

Exit the database

exit
Copy after login

Exit the docker container

control + p + q
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template