Home >Database >Mysql Tutorial >How to use Docker to build mysql that can be accessed externally
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
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;
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
Try to connect with navicat
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!