title: MySQL doesn't work in terminal but can connect to database and use query
body: <p>I tried to use the command line to start MySQL in MacOS, but it always showed error an error:</p>
  <pre><code>~ mysql.server start
  my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
  my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
  Starting MySQL
  .my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
  my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
  my_print_defaults: [ERROR] Found option without preceding group in config file /etc/my.cnf at line 1!
  my_print_defaults: [ERROR] Fatal error in defaults handling. Program aborted!
  </code></pre>
  <p>I searched the error and most of the answers is adding [mysqld] in my.cnf,  I checked my.cnf file, it already had [mysqld] tag.
  This is my.cnf, it didn’t exist before I reinstall MySQL by <a href="https://gist.github.com/lucascaton/3373792" rel="nofollow noreferrer">Reinstalling Mysql on Mac via Homebrew · GitHub</a></p>
  <blockquote>
  <p>Default Homebrew MySQL server config</p>
  <p>[mysqld]</p>
  <p>Only allow connections from localhost</p>
  <p>bind-address = 127.0.0.1</p>
  <p>secure_file_priv=''</p>
  </blockquote>
  <p>Then I found another possible way is to change the character set to ANSI or ASCII, so I checked my.cnf file, but it's ASCII encoding.</p>
  <pre><code>~ enca -L none /usr/local/etc/my.cnf
  7bit ASCII characters
  </code></pre>
  <p>I tried to stop and restart, still got the same error. BTW,  I used another command and it showed a different error:</p>
  <pre><code>~ service mysql restart
  zsh: command not found: service
  </code></pre>
  <p>So I changed the <code>$PATH</code> config, it's still not working.</p>
  <p>Finally I found I can start MySQL in system preferences, but the configuration file was blank, I changed it to <code>/usr/local/etc/my.cnf</code> and ran it, it shows MySQL server starting. I can use a query and connect to database.</p>
  <p>However, I still got the same error when I used a command like above, and also I can't use data export in MySQL Workbench. I ran <code>/usr/local/mysql-8.0.12-macos10.13-x86_64/bin/mysqldump</code> , it showed the same error.</p>
  <p>Please help.</p>