Skip to main content

Change Default Password for MySQL

tip
  • The following steps take the root password as tC9S86SFWxga as an example. The root password must be modified in the actual configuration

    • To ensure compatibility, avoid using special characters such as "$", "&", "!" or "@" when customizing passwords. These characters may interfere with regular expression parsing. Please use hyphens "-" or underscores "_" instead
  • It is recommended to data backup in advance before operation.

  1. Enter the sc container and log in to MySQL

    docker exec -it $(docker ps | grep sc | awk '{print $1}') bash -c 'mysql -uroot -p123456 -h127.0.0.1'
  2. Change MySQL password

    GRANT ALL ON *.* to root@'%' IDENTIFIED BY 'tC9S86SFWxga';
  3. Modify the docker-compose.yaml file and add environment variables and port mapping

    Default path of docker-compose.yaml file: /data/hap/script/docker-compose.yaml

    Add the environment variable ENV_MYSQL_PASSWORD under the core service to specify the new password for MySQL

    ENV_MYSQL_PASSWORD: "tC9S86SFWxga"

Add a new port mapping under the sc service and map the 3306 port in the container (if there is no need to access MySQL externally, there is no need to add this port mapping)

- 3306:3306
docker-compose.yaml configuration file example
version: '3'

services:
core:
image: nocoly/core:7.4.2
environment: &app-environment
ENV_ADDRESS_MAIN: "https://example.domain.com"
ENV_APP_VERSION: "7.4.2"
ENV_API_TOKEN: "******"
ENV_MYSQL_PASSWORD: "tC9S86SFWxga" #Add a new variable and change it to the actual password.
ports:
- 8880:8880
volumes:
- ../data:/data/hap/data

sc:
image: nocoly/sc:3.2.0
environment:
<<: *app-environment
ports:
- 3306:3306 #Added mysql port mapping. If external access to mysql is not required, there is no need to add this port mapping.
volumes:
- ./volume/data/:/data/
  1. Restart the microservice in the directory where the installation manager is located to take effect.

    bash service.sh restartall