mysqlInitialized checks if the MySQL data directory has been initialized. We use sudo ls because /var/lib/mysql is typically only readable by the mysql user, so filepath.Glob from a non-root process would silently fail.
()
| 695 | // We use sudo ls because /var/lib/mysql is typically only readable by the |
| 696 | // mysql user, so filepath.Glob from a non-root process would silently fail. |
| 697 | func mysqlInitialized() bool { |
| 698 | out, err := exec.Command("sudo", "ls", "/var/lib/mysql").CombinedOutput() |
| 699 | if err != nil { |
| 700 | return false |
| 701 | } |
| 702 | // If the directory has any contents, consider it initialized. |
| 703 | // mysqld --initialize-insecure requires an empty directory. |
| 704 | return strings.TrimSpace(string(out)) != "" |
| 705 | } |