0

I've read through a lot of alternative solutions but I haven't found anything specific to my problem. I'm using Windows PowerShell, and I need to restore/populate my DB Docker container that I created using the following code below.

docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=root -p 3306:3306 -e MYSQL_DATABASE=DB -e MYSQL_USER=PASSWORD -e MYSQL_PASSWORD=PASSWORD -d mysql:8

Then to populate my DB (Restoring data from an sql dump file) I enter in the following code below to point my .sql file to the DB container I created.

p.s. I have to place in dbl quotes due to windows syntax. I also can't place in the following character '<' before entering in my path because it's improper syntax for Docker on Windows)

docker exec -i some-mysql sh -c "exec mysql -uroot -p "$root"" "C:/filePathHere/all-databases.sql"

After I hit enter I receive the fallowing error below

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

Even after creating a new DB connection and adding in a new user/password, which I use root for both User/Pwd. I still get denied access.

Anyone know what I may be doing wrong ? It's important I populate my DB container this way and avoid manually restoring the dump file.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Monttana16
  • 307
  • 2
  • 9
  • @RiggsFolly Please read the contents of what I'm asking. All the syntax that's provided in what you considered a duplicate question is for a Linux OS. I need assistance with Windows. That link is something I've already read into and it did not provide me a solution to my problem. – Monttana16 Sep 08 '22 at 07:23
  • Apart from the file paths its all Docker code. That is not OS dependant – RiggsFolly Sep 08 '22 at 09:04
  • @RiggsFolly thank you for re-opening my question. I understand what you mean as Docker code isn't OS dependent, however the syntax for the paths of pointing a .sql file to a docker container, has only ever shown syntax of an operator '<' placeFile here which I can't do for windows and I havent found a solution for this. Do you perhaps know a solution ? Or a better way to ask my question to get a solution for this ? – Monttana16 Sep 09 '22 at 13:18

1 Answers1

1

I've found the solution to my question, and first to start off, the cmmd using the fallowing syntax with an '<' operator is not supported in PowerShell v1 and as of v5, it's still not... You can either use regular cmmd line or place your docker cmmd syntax inside a .bat file and run it through windows powershell.

You cab refer to this site that provides the fallowing solution for the file path syntax using windows (I provided the code from the link below). Windows: Back up & restore MySQL data from Docker container

And if anyone is getting a similar error

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

A solution that worked for me was to add the fallowing cmmd mysql -u root to your Restore cmmd. Found this solution via this link here Access denied for user 'root'@'localhost'

BACK-UP

C:\docker\directory> docker ps

C:\docker\directory> docker exec container-id /usr/bin/mysqldump -u username database-name > dump.sql

RESTORE

C:\docker\directory> docker ps

C:\docker\directory> docker exec -i container-id /usr/bin/mysql -u username database-name < dump.sql

If you want to use docker-compose command

    # To BACK BACKUP
C:\docker\directory> docker-compose exec -T container-name /usr/bin/mysqldump -u username database-name > dump.sql

    # To ROLLBACK 
C:\docker\directory> docker-compose exec -T container-name /usr/bin/mysql -u username database-name < dump.sql
Monttana16
  • 307
  • 2
  • 9