Reputation: 181
In order to load databases to mysql using terminal, as shown here, the sql file must be already in the server? Or I can upload from my local pc?
Upvotes: 1
Views: 351
Reputation: 9277
If you have mysql installed in your local machine: then you can at once run the import command from local machine's command line
mysql -hmy_server -umy_user -p database_name < full/path/to/file.sql
or you can just go to the directory where your sql file exists and run
mysql -hmy_server -umy_user -p database_name < file.sql
(password will be required after hitting Enter). This way the file will be imported into the remote database from your local computer.
No mysql is installed in your local machine: in this case you have to manually upload the file into the server with some ftp client and then connect remotely(e.g. by Putty) and run similar command
mysql -umy_user -p database_name < path/to/sql/file.sql
Upvotes: 1
Reputation: 77926
NO, the SQL file or SQL script file generally can be present in your machine. When you execute the command, said sql script gets executed against the database.
mysql -u user -p -h servername DB < [Full Path]/test.sql
Upvotes: 0
Reputation: 9353
Assuming the file contains SQL statements it can go anywhere. What is important is that the MySQL client you use to read the file can access the database server - usually on port 3306 for MySQL.
Upvotes: 1
Reputation: 102
Yes. You can SCP or SFTP it to the server, but that command expects a file on the machine. In fact, that particular command expects it to be in the same directory that you are in.
Upvotes: 1
Reputation: 483
On the server, unless your local directory is accessible via network to the server (i.e. network share on another machine which is mapped to some address on your server - convoluted but essentially possible).
Basically, just upload the file to the server and run the command locally there.
Upvotes: 0