Reputation: 745
I am trying to use MySQL command line client to execute a procedure. The procedure helloworld()
is executing fine in MySQL query browser.
db scheme selected in query browser:
DELIMITER $$
DROP PROCEDURE IF EXISTS helloworld$$
CREATE PROCEDURE helloworld()
BEGIN
SELECT 'helloworld';
END$$
When I call helloworld()
it returns helloworld. I am saving the procedure as helloworld.sql
saved in SQL SCRIPT FILE ANSI .sql in desktop
Now I am trying to access the .sql file saved in desktop from cmd client giving the password that connects successfully
Now when I type
ENTER PASSWORD:******
Your Mysql connection id is 43
Server Vesion 5.5.24
mysql> SOURCE helloworld.sql
ERROR failed to open file helloworld.sql Error 2
Should I give the path of the file?
Upvotes: 4
Views: 10504
Reputation: 9201
In my case, the solution was in fact to change the ownership of the source file to be the username of the user who was logging into the machine and running the command via the mysql
terminal. I am using CentOS Linux with MariaDB/MySQL5.6.
The command that worked to remove the error was: sudo chown username:username sourcefile.sql
I also tried changing it to mysql:mysql
instead of username:username
, but the error persisted until I used sudo chown username:username sourcefile.sql
Upvotes: 1
Reputation: 165
I faced similar problem. The solution worked for me is
sudo chown root:root /Full/path/to/sqlfile.sql
Sudo su;
mysql -u root -p < /Full/path/to/sqlfile.sql
If it helps anyone in future.
Upvotes: 1
Reputation: 1
i have also got the same message when i try to do the operation from mysql console but when i open the command prompt and do the same steps its working well not getting any error
C:\Users\SubhenduD>cd ../
C:\Users>cd ../
C:\>cd \xampp\mysql\bin
C:\xampp\mysql\bin>mysql -u -root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 68
Server version: 5.6.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> use balticktravels;
mysql> source balticktravels.sql;
Upvotes: -1
Reputation: 425318
It's a file permission issue.
The mysql process, not the user of the shell running the mysql command interface, needs permission to read the file.
Upvotes: -1
Reputation: 16569
Try:
/path/to/file/helloworld.sql:
USE `yourdb`;
DELIMITER $$
DROP PROCEDURE IF EXISTS `helloworld`$$
CREATE PROCEDURE `helloworld`()
BEGIN
SELECT 'helloworld';
END$$
DELIMITER ;
Then from the command line try:
Your Mysql connection id is 43
Server Vesion 5.5.24
mysql> SOURCE /path/to/file/helloworld.sql
Upvotes: 1