I am getting following error while executing my mysql query via a .sql script, but couldn’t tell what is causing this error.
I am using mysql Ver 8.0.23 for macos10.15 on x86_64 (MySQL Community Server – GPL)
Error :
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 ‘/Users/shivamshekhar/Documents/Others/chat-app-backend/scripts/mysql/db.sql’ at line 1
.sql file
CREATE DATABASE IF NOT EXISTS `chat_app`; USE `chat_app`; CREATE TABLE IF NOT EXISTS `user_details` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, `name` VARCHAR(255) NOT NULL, `password` VARCHAR(255) NOT NULL, `created_at` DATETIME DEFAULT CURRENT_TIMESTAMP, `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, INDEX `idx_name` (`name`), CONSTRAINT `uc_name` UNIQUE (`name`) );
Terminal command :
mysql -u admin -ppassword -e ~/Documents/Others/chat-app-backend/scripts/mysql/db.sql
Advertisement
Answer
-e
command means “execute the command”, not “load and execute source file”.
Send the source file to the client via stdin:
mysql -u admin -ppassword < ~/Documents/Others/chat-app-backend/scripts/mysql/db.sql
Or provide according command to the client:
mysql -u admin -ppassword -e "SOURCE ~/Documents/Others/chat-app-backend/scripts/mysql/db.sql"