Docker install mysql 5.7
Pull the mirror
Docker pull mysql: 5.7Copy the code
Creating a mysql container
Docker run -itd --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7Copy the code
Set the password of user root to 123456
Configuring Remote Access
docker exec -it mysql bash
Copy the code
- Enter the mysql container
mysql -uroot -p
Copy the code
- Log in to mysql and enter the password to log in to mysql
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
Copy the code
- {username} : indicates the username for remote access. Root is not recommended.
- {password} : indicates the login password for remote access.
- ‘%’ : indicates all IP addresses. If possible, specify the IP address or IP address segment
FLUSH PRIVILEGES;
Copy the code
- Refresh the permissions
Note: all mysql commands are required; At the end
test
Mysql -h localhost -uroot -p mysql -h IP -u username -p password # IP: use PC public IP # username: create account # Password: indicates the password used to create the accountCopy the code
exit
exit;
Copy the code
Note: Ali/Tencent server security group release port 3306