What does the symbol '<' mean on the mysql command line and where is the imported file saved? - mysql

I gather from the context of the following page https://github.com/AtomBoy/double-metaphone that the following command has something to do with adding a custom function to the mysql server. Here is the command that I don't understand:
mysql yourDataBaseName -u root -p < metaphone.sql
I successfully ran the command, and installed the function, however I'm still unclear on the complete function of the less than sign. I understand that I am importing a .sql file. In this case the sql file is a function.
Where is this function saved?

Related

How to connect to MYSQL database on server via Terminal on Macbook?

Is there a way to connect to my mysql database and do sth on tables via terminal?
Yes. In your terminal start the mysql prompt using
mysql --user=user_name --password=your_password db_name
Where db_name is the name of your database and user_name and password are your username and password.
You can then run SQL statements/queries from .sql files
mysql db_name < script.sql > output.tab
Where db_name is your database name, script.sql is a file containing your script, and output.tab (optional) is a file in which to dump the output of the query
You then simply place an SQL query in a file and run it.
If you get the error mysql: command not found, this is because the mysql executable cannot be found in your system PATH. If so, you need to run the following command to add the mySQL folder to the PATH, so that OS X knows to look there for the executable
export PATH=${PATH}:/usr/local/mysql/bin
Where /usr/local/mysql is the location of your mysql installation.
You can add this to your .bash_profile file (located at ~\.bash_profile, or you can create it) in order to have it run every time you start a new terminal. Otherwise you'll have to enter it manually before using the mysql command
Once you've entered this command (or added it to .bash_profile) you can use the mysql command as above
Alternately navigate to /usr/local/mysql/bin (or the location of your mysql install) and use the command
./mysql command
Instead of
mysql command
As above (where command is the command described in the first half of this post). This runs the mysql binary directly, rather than searching for it in the PATH

Mysql command returns no errors and doesn't import the sql file. Why?

I'm executing on a Centos Linux server this command:
mysql -u root -p mydatabase < dump.sql
I enter the password. It seems that all is ok because I absolutely get no errors, no messages that something happened. But sadly, the file is not imported!
Tryed in different ways:
-Putting the sql file in another location.
-Creating the DB first and than without the DB.
-Avoiding the dbname
-Adding max_allowed_packet=800M in /etc/my.cnf (because the file is 490mb)
-Restarted Mysql. But nothing to do. No errors, no import. I'm stuck and in panic. What to do? ?
If you have already created database then use below steps to import data from .sql file
DataBase to use:
use DataBaseName;
Give the source file path
source /path/to/dump.sql;
Hope this will help

Notepad++ and MySQL

I'm trying to work with a MySQL server through the notepad++ console. I can navigate to the bin directory of MySQL server, but when I run MySQL:
mysql -u root -p
The console just says Process started >>> and then doesn't ask for my password, or accept any other input. What is going on? I'd much rather work through the notepad++ console than the windows command prompt.
MySQL is using file IO similar to *nix systems or old MS-DOS. The "<" is actually a command line directive, but you're telling Notepad++ to run the mysql.exe program directly (bypassing the command line altogether, so the input directive will be completely ignored).
The solution is to create a batch file.
Example (a file named "C:\exec_mysql.bat"):
"C:\mysql\bin\mysql.exe" -u root < %1
PAUSE
Then in Notepad++ execute your batch file instead:
"C:\exec_mysql.bat" "$(FULL_CURRENT_PATH)"
This will pass the parameter as expected, launch MySQL and pass in the file.

mysql won't import database dump file on Windows XP

I created a data base using mysql. I used MySQLDump to create one database backup file in text format (MySql 5.5 on Windows XP). The database is local on my machine (local host).
I am having trouble using the MySQL command to load the dump file to restore the database. I have done the following:
Research stack overflow for how to do it. I noticed there's a bug using the MySQL command to restore the data from a post. Before I run the command, I DROP the database and CREATE the database using MySQL workbench.
I type the following command in the DOS prompt to restore the database:
mysql -u root -p -h localhost -D matlab_data -o < backup.sql
backup.sql is a the backup file in text format created by MySqlDump.
I am then asked for the password which I enter. I get the DOS prompt right away with no error message. I've waited several hours for the command to run and the database is still empty.
I have tried various command formats over the last few days. If I enter incorrect data in the command line (non existen file, database, etc), I get an error message.
I feel I would not see the DOS prompt until the database is restored. If I don't DROP and CREATE the database, I get an error message. Otherwise, not.
Does anybody have any idea what the issue is? I realize that I could be making a stupid mistake.
Thank you for your help.
shell into the mysql console and run the sql file as this
If you are already running mysql, you can execute an SQL script file using the source command or . command:
mysql> source file_name
mysql> \. file_name
note that file_name must be an absolut path

How can I run multiple Stored Procedures Files & Triggers (.sql) From MySQL Workbench

I am trying to run a set of sql files with stored procedures and triggers in my windows XAMPP environment. Some suggested to me using a batch script but I do not know how to do this in windows.
Is it possible to run all these .sql files from within MySQL Workbench? How? If not, can anyone tell me how to run a batch file within windows?
Thank you.
It seems Workbench doesn't support the command "SOURCE" so the next best thing is is (at least in windows) is to run a batch job. Simply create a new .sql file and add the full path to each .sql file like so:
Create the batch file:
In windows, the batch file can be a .sql with the sql comman SOURCE which calls the other .sql files, like so:
create run.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_delete.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_insert.sql
SOURCE C:\xampp\htdocs\mysite\sql\procs\sp_article_load.sql
Open Command Line and CD to MySQL Folder
Open the command line, and cd to MySQL. If you are using XAMPP, the command/location should be something like:
cd C:\xampp\mysql\bin\
Execute the Batch File by pressing ENTER
Last, simply load mysql and run the batch file using the following command:
mysql -u root -h 127.0.0.1 my_database_name -vvv < C:\xampp\htdocs\mysite\sql\procs\run.sql
The execution above means the following:
mysql -u <username> -h <host> <database> -vvv < <batch_path_file_name>
-vvv shows all the queries being executed and the rows affected for debugging.
That's it. All .sql files mentioned in the run.sql file will be executed.