要安装Docker并设置MySQL数据库,你可以按照以下步骤进行操作:
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo docker pull mysql:latest
sudo docker run -d --name mysql-container -e MYSQL_ROOT_PASSWORD=your_password -p 3306:3306 mysql:latest
这将下载最新的MySQL镜像并在容器中运行MySQL。请将 your_password
替换为你想要设置的MySQL root密码。
sudo docker exec -it mysql-container mysql -uroot -p
输入之前设置的密码以连接到MySQL数据库。
CREATE DATABASE your_database;
CREATE USER 'your_user'@'%' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database.* TO 'your_user'@'%';
FLUSH PRIVILEGES;
请将 your_database
替换为你想要创建的数据库名,your_user
替换为你想要创建的用户名,your_password
替换为你想要设置的密码。
通过以上步骤,你已经成功安装了Docker并设置了MySQL数据库。