import_ubuntu.sh 547 B

12345678910111213141516171819202122232425262728
  1. #!/bin/bash
  2. # Ubuntu 22.04 文件格式和 Win 不同!
  3. #
  4. # 安装转码工具
  5. # sudo apt install dos2unix
  6. #
  7. # 转码
  8. # sudo dos2unix import_ubuntu.sh
  9. #
  10. # 执行
  11. # sudo sh import_ubuntu.sh
  12. # MySQL 8.x 登录凭据
  13. username="root"
  14. password="xxxxxxxx"
  15. database="backendsys"
  16. # SQL文件所在的目录
  17. sql_dir="/home/www/project/BackendSys/db/"
  18. # 遍历目录中的所有.sql文件
  19. for file in ${sql_dir}*.sql; do
  20. echo "Importing file: $file"
  21. mysql -u $username -p$password $database < $file
  22. done
  23. echo "All SQL files have been imported."