I'm using Ubuntu 16.04 and I'm able to use MySql from the command line fine. I can create a db, add tables, add rows to tables, get queries etc.
What I can't do is write an sql file and run it.
From a regular terminal I change into the directory containing my script test.sql
Then I run mysql -u root -p > test.mysql and it asks me for my password. If I put the wrong password I get an error and if I put the correct password nothing happens, the terminal behaves as if its expecting further input.
If I have MySql started and I do
mysql>SOURCE /home/ryan/MYSQL_Scripts/test.sql
I get Failed to open file '/home/ryan/MYSQL Scripts/test.sql', error: 2
I know this means the file could not be found or supposedly does not exist yet from my explorer I right clicked on the file to get info on its path so I think the path is okay.
I don't think there's anything wrong with my script since I can run the commands individually from the mysql prompt. Here's my script:
USE first_db;
CREATE TABLE Department(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL);
CREATE TABLE Employees(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(30) NOT NULL,
department_id INT(6) NOT NULL);
INSERT INTO Department (name) VALUES ("Fire");
SELECT * FROM Department;
I of course have a db, first_db, already created and am able to interact w/ it from the mysql prompt I just need help using mysql scripts.
Some advice would be much appreciated. Thanks!
`
>:mysql -u root -p < test.mysqlOtherwise you are redirecting your stdout from mysql to that file (and blowing away it's content when you do so).