Skip to main content

Change Default Password for MySQL

tip
  • Using tC9S86SFWxga as an example for the root password, please remember to change it in your actual configuration.

    • To ensure compatibility and security, avoid special characters like "$", "&", or "@" in your custom passwords. These characters can interfere with regular expression parsing and may not be correctly passed to the container. Use hyphens "-" or underscores "_" instead.
  • Advance data backup is recommended before operation.

Enter the hap-sc container and log in to MySQL

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

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

    The default path for file docker-compose.yaml: /data/hap/script/docker-compose.yaml

    Add a new environment variable ENV_MYSQL_PASSWORD to specify the new password for MySQL under the app service.

    ENV_MYSQL_PASSWORD: "tC9S86SFWxga"

    Add port mapping under the sc service to map port 3306 out of the container (you can leave port mapping off if don't need external access).

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

    services:
    app:
    image: nocoly/hap-community:5.8.3
    environment:
    ENV_ADDRESS_MAIN: "https://hap.domain.com"
    ENV_APP_VERSION: "5.8.3"
    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/hap-sc:3.0.0
    environment:
    <<: *app-environment
    ports:
    - 3306:3306 # Add MySQL port mapping. If external access to MySQL is not required, there is no need to add this port mapping
    volumes:
    - ./volume/data/:/data/
  3. Restart the microservice in the directory of Install Manager to take effect.

    bash service.sh restartall