Initializing the Database
This section uses the three MySQL databases deployed in Deploying MySQL Pod in the K8s Cluster as an example. The three MySQL databases are automatically initialized when they are started for the first time. You can skip the following initialization operations.
If you use other MySQL images that are not automatically initialized or the MySQL databases installed in your environment have not been initialized, perform the following operations:
Initialize the following three sample databases one by one:
- Since the databases are deployed in pods, run the following command to access the pod:
1kubectl exec -it <pod_name> -n <spaces_name> -- /bin/bash
For example:
1 2 3
kubectl exec -it mysql-1 -n ns-mysql-test -- /bin/bash kubectl exec -it mysql-2 -n ns-mysql-test -- /bin/bash kubectl exec -it mysql-3 -n ns-mysql-test -- /bin/bash
- After accessing the pod, initialize it.
1mysqld --defaults-file=/etc/my.cnf --initialize
- View the password of the root user of the MySQL database after initialization.
1cat /data/mysql/log/mysql.log - Use the password to log in to the MySQL database.
1mysql -uroot -p
- Execute the following statements to initialize the root user:
1 2 3 4
alter user 'root'@'localhost' identified by "test123"; create user 'root'@'%' identified by 'test123'; grant all privileges on *.* to 'root'@'%'; flush privileges;
Parent topic: Deploying MGR