1. Use the mysql/mysql-server:latest image to quickly start a mysql instance
docker run --name ilink_user_01 -e mysql_root_password=123456 0d 0p 3307:3306 mysql/mysql-server:latest
ilink_user_01 is the container Name, specify
123456 as the password of the database root through the --name command, specify the environment mysql_root_password as 123456 through -e, -e (specify the environment variable in the container)
-d Using the -d parameter, the container will enter the background. The user cannot see the information in the container and cannot perform operations.
3307:3306 is Port mapping, specify the local host port 3307 to be mapped to the container's 3306 port
2. Enter the instance to modify the mysql configuration information
docker exec -it ilink_user_01 bash
exec can directly execute human commands inside the container
Use the parameter -it to open the interactive terminal of the container, and users can easily communicate with Containers interact without affecting the normal operation of other applications in the container
3. View all users in the mysql database
select distinct concat('user: ''',user,'''@''',host,''';') as query from mysql.user;
4. Modify the root user of mysql to allow users to log in from any IP
update mysql.user set host='%' where user='root'; flush privileges;
5. Use navicat to test Connection
The authentication plugin 'caching_sha2_password' appears, because the mysql image is encrypted using caching_sha2_password, and navicat does not support the caching_sha2_password encryption method,
6. Solve the authentication plugin 'caching_sha2_password'
alter user 'root'@'%' identified with mysql_native_password by '123456';
7. Reuse navicat to connect
The above is the detailed content of How Docker creates and runs multiple mysql containers. For more information, please follow other related articles on the PHP Chinese website!