When attempting to connect to a MySQL database remotely using the command mysql -u root -p, users may encounter the error message:
Found option without preceding group in config file: /etc/mysql/my.cnf at line: 1
This error occurs when the my.cnf configuration file is missing the [mysqld] header. The my.cnf file contains configuration settings for MySQL, and each section must be enclosed within square brackets ([]) with the corresponding section name.
To resolve this issue, add the [mysqld] header as the first line in the /etc/mysql/my.cnf file.
[mysqld] ... (remaining configuration settings)
For example, if you wish to set the default time zone:
[mysqld] default-time-zone = "+08:00" ... (remaining configuration settings)
After making the necessary changes to the my.cnf file, restart the MySQL service to apply the new settings.
Ubuntu/Debian
sudo mysqld stop sudo mysqld start
CentOS/Red Hat
sudo service mysqld stop sudo service mysqld start
Once the MySQL service has been restarted, you should be able to establish a remote connection without encountering the error message.
The above is the detailed content of \'Found Option without Preceding Group in my.cnf: Why and How to Fix it?\'. For more information, please follow other related articles on the PHP Chinese website!