docker pull mysql
The default is to download the latest stable version
docker run --name dockermysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysqlpassword -d mysql
--name is the alias of the image
-p maps 3306 to 3306 (docker is a virtual machine with its own port)
-e MYSQL_ROOT_PASSWORD=mysqlpassword Set the mysql server password (required later, be sure to remember)
-d Backend startup
Start the mirror name (can Replace with id)
docker ps
is as follows:
docker exec -it dockermysql bash
dockermysql is the name of the image, you can use id instead
mysql -u root -p
and enter the password set above
Switch database (the default should be this, it’s okay not to switch, just switch it to be on the safe side)
use mysql;
Change remote link authorization
grant all privileges on *.* to 'root'@'%';
The reason for the error is a problem with the encryption method
Check it:
select Host,User,plugin from user;
The result before modification is as follows:
Execute the modification command:
alter user 'root'@'%' identified with mysql_native_password by 'yourPassword';
Change it to your mysql password
The result after successful modification is as follows:
The above is the detailed content of How to install mysql8 and configure remote connection with docker under Linux. For more information, please follow other related articles on the PHP Chinese website!