MySQL导入.sql文件执行命令后无响应问题求助
Hey there! Let's break down why your SQL import command is just dropping you back to the prompt without any feedback, and fix it up step by step:
Common Causes & Fixes
Double-check your file path
Relative paths depend on your current working directory, which might not be where you think it is. Instead of usingDocuments/Project/Projects-db/file.sql, try the full absolute path (replaceuserwith your actual username):sudo mysql -u root -p database_name < /home/user/Documents/Project/Projects-db/file.sqlYou can confirm the path is valid first by running
ls Documents/Project/Projects-db/file.sql—if it throws a "No such file or directory" error, your path is incorrect.Ensure the target database exists
MySQL won’t automatically createdatabase_nameduring import. To verify:- Run
sudo mysql -u root -p, enter your password to access the MySQL shell. - Run
SHOW DATABASES;to check if your target database is listed. - If it’s missing, create it with
CREATE DATABASE database_name;, exit the shell, and retry the import.
- Run
Use the
sourcecommand for visible feedback
The redirect (<) method often hides error messages. A more transparent approach is to import directly from the MySQL shell:sudo mysql -u root -p database_nameAfter entering your password, run this in the shell:
source /home/user/Documents/Project/Projects-db/file.sql;This will display any errors (like invalid SQL syntax or missing dependencies) that might be causing the silent failure.
Check file permissions
Make sure the SQL file is readable by the MySQL process. Run:ls -l Documents/Project/Projects-db/file.sqlLook for the
r(read) flag for your user or others. If it’s not readable, fix it with:chmod +r Documents/Project/Projects-db/file.sqlVerify the SQL file isn’t empty or corrupted
Quick check the file content with:cat Documents/Project/Projects-db/file.sqlIf it’s empty or full of unreadable characters, you’ll need to use a valid copy of the SQL dump.
内容的提问来源于stack exchange,提问作者Omer

