Skip to content

Instantly share code, notes, and snippets.

@paulmwatson
Last active July 8, 2021 10:28
Show Gist options
  • Save paulmwatson/75eee987347a5c31bc7025a161b66e5a to your computer and use it in GitHub Desktop.
Save paulmwatson/75eee987347a5c31bc7025a161b66e5a to your computer and use it in GitHub Desktop.
Accessing MySQL 5.1 data without the root password

Alter existing mysql database without root password

Unzip oldwebsitedata.tar.gz into this directory so that you end with ./mnt/mysql-snapshot-2015-03-31/data

Then run:

docker-compose run mysql bash

Once inside the container run:

mysqld_safe --skip-grant-tables &

Press enter/return. Now run:

mysql -u root

You are now in the mysql shell. show databases; will show:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| pmg_drupal         |
| pmg_test           |
+--------------------+

You can now alter the root user password (this is MySQL 5.1 syntax):

UPDATE mysql.user SET Password=PASSWORD('newpassword') WHERE User='root';
FLUSH PRIVILEGES;

Exit out of the mysql shell and Docker container.

The database data files in the host have been modified so you don't need to do this again for those data files.

Now you can run mysql normally:

 docker-compose up

 docker exec -it CONTAINERID bash
 mysql -u root -p

Background

The key to making this work was that vsamov/mysql-5.1.73 needed mysql_upgrade on the PMG Drupal database but you need the root password to run that upgrade. grugnog/mysql-5.1 works fine with the PMG Drupal data.

version: '3.1'
services:
mysql:
image: grugnog/mysql-5.1
environment:
MYSQL_ROOT_PASSWORD: itdoesntmatter
ports:
- "3307:3306"
volumes:
- ./mnt/mysql-snapshot-2015-03-31/data:/var/lib/mysql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment