From Workbench: File > Run SQL Script -- then follow prompts
From Windows Command Line:
Option 1: mysql -u usr -p
mysql> source file_path.sql
Option 2: mysql -u usr -p '-e source file_path.sql'
Option 3: mysql -u usr -p < file_path.sql
Option 4: put multiple 'source' statements inside of file_path.sql (I do this to drop and recreate schemas/databases which requires multiple files to be run)
mysql -u usr -p < file_path.sql
如果从命令行得到错误,请确保之前运行过
cd {!!>>mysqld.exe home directory here<<!!}
mysqld.exe --initialize
mysql -u root -proot -D database < /path/to/script.sql
你可能会得到这样的错误:如果你有特殊字符,主要是' "
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '/path/to/script.sql' at line 1
所以我建议使用这样的命令:
echo "source /path/to/script.sql" | mysql -u root -proot -D database