修改my.cnf后URL路径显示主目录,无法移除该怎么办?
Hey there, let's tackle this problem step by step. I've run into similar config file hunting issues with MySQL before, so I know how frustrating it is when you can't track down a change you made months ago. Here's how to get to the bottom of it:
Step 1: Locate all possible my.cnf files MySQL uses
MySQL reads config files from multiple locations depending on your OS and installation method. Use these commands to find exactly which files your instance is loading:
Check via terminal command:
Run this in your shell to see the default config file search order MySQL follows:mysql --help | grep -A 1 "Default options"You'll get output like this, listing all potential config paths:
Default options are read from the following files in the given order: /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnfFind the actively used config file directly in MySQL:
Log into your MySQL shell withmysql -u [your-username] -p, then run this query to get the exact path of the config file your running instance uses:SHOW VARIABLES LIKE 'config_file';This is the most reliable way to pinpoint the file you modified earlier.
Step 2: Fix the problematic pid-file configuration
Once you've found the correct my.cnf file, open it with a text editor (e.g., sudo nano /path/to/your/my.cnf). Look for the invalid line you added:
pid-file edit
This is a malformed setting—pid-file requires a valid file path (like pid-file = /var/run/mysqld/mysqld.pid), not the word "edit". Remove this line entirely, or replace it with a proper pid file path if you need that configuration.
Step 3: Restart MySQL to apply changes
Save the corrected config file, then restart your MySQL service to make sure changes take effect. Use the command matching your OS:
- For systemd-based systems (Ubuntu 16.04+, CentOS 7+):
sudo systemctl restart mysql - For older init.d systems:
sudo service mysql restart
After restarting, check if the {username} path issue is resolved. If it persists, double-check that you modified the correct config file (use the SHOW VARIABLES LIKE 'config_file'; query again to confirm) and that the invalid line was fully removed.
内容的提问来源于stack exchange,提问作者codo7081

