You may need to provide mysql username, password and hostname, use: $ mysql -user=your-user-name -password=your-password Invoke it from the prompt of your command interpreter as follows: $ mysql mysql is command line and it is very easy to use. To list all the databases execute this command in terminal: mysql -u root -p -e 'show databases' It will silently create a database mydb without giving any message/output. To create database mydb execute following command in terminal: mysql -u root -p -e 'create database mydb'
If you want to select all the information from person and want to save in a file: mysql -u root -p -e 'Select * from person' mydb > personinfoĪnd of-course you can create a database using terminal itself If you want to insert values in person: mysql -u root -p -e 'Insert into person(PersonID,LastName,FirstName) Values(100,'Kumar','Saurav')' mydb Similary you can execute any query you want. Where root is the username, mydb is the name of the database. If you want to create a table person then: mysql -u root -p -e 'Create table person(PersonID int, LastName varchar(255), FirstName varchar(255))' mydb Syntax: mysql -u user_name -p password -e 'SQL Query' databaseĬlearificance: -u : Specify mysql database user name
Here is the syntax to execute sql statement from terminal