user3427658
user3427658

Reputation: 301

What is the use of < symbol in mysql?

The symbol < was used following query ,But i could not find why it is used and what its purpose

c:\>mysql -u root -p < create_database.sql

in create_database.sql consist of following

CREATE DATABASE sonar CHARACTER SET utf8 COLLATE utf8_general_ci;
CREATE USER 'sonar' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'%' IDENTIFIED BY 'sonar';
GRANT ALL ON sonar.* TO 'sonar'@'localhost' IDENTIFIED BY 'sonar';
FLUSH PRIVILEGES;

Upvotes: 0

Views: 131

Answers (2)

Boris Bera
Boris Bera

Reputation: 898

The < character has nothing to do with mysql. It is part of the command line interface. It does stream redirection.

The mysql -u root -p < create_database.sql line takes the contents of the create_database.sql file and sets it as the input of the mysql -u root -p command. The mysql command reads the contents of the file as if it were typed in by the user.

Upvotes: 0

Barmar
Barmar

Reputation: 781068

That's Unix shell and Windows cmd.exe syntax. It means that the file after < should be used as standard input to the command. So it runs the mysql command, and the contents of the create_database.sql file will be read as input by mysql, and it will perform those queries.

Upvotes: 2

Related Questions