In docker mysql initializes and starts the failed problem solution

  • 2020-05-17 07:14:47
  • OfStack

Recently, when I was working on a project, I encountered such a problem that mysql in docker could not be started. After searching information on the Internet, I finally solved this problem. If I record it here, I may be able to help you.

There is one mysql service in docker, whose data file is a file hanging outside the host. root in docker has access to this data file. However, when mysql in docker accesses the data file, mysql indicates insufficient access, so mysql can only be started as root user.

Data initialization:

mysql_install_db --user=root --explicit_defaults_for_timestamp=1

Start as root user after initialization

mysqld --user=root --explicit_defaults_for_timestamp=1

mysql started normally.

There are three main startup modes:

1. Start systemctl start mysqld using systemctl
2, using a script start/etc/inint d/mysqld start
3. Start with safe_mysqld or mysqld --user=mysql

There are also three ways to close:

1. Close systemctl stop mysqld with systemctl
2, using a script to close/etc/inint d/mysqld stop
3, mysqladmin shutdown

Note: services started using safe_mysqld or mysqld --user=mysql can only be closed by mysqladmin shutdown, not by systemctl or script.

mysqladmin shutdown can shut down the above three services. Scripts can turn off services opened by systemctl, and systemctl can also turn off services opened by scripts

Thank you for reading, I hope to help you, thank you for your support of this site!


Related articles: