Execute SQL script from command line:

Take a look at the sqlcmd utility. It allows you to execute SQL from the command line.

  • start your local server
  • open command prompt

  •  Microsoft Windows [Version 10.0.18362.900]  
     (c) 2019 Microsoft Corporation. All rights reserved. 
     C:\Users\Lenovo>cd../../../.. 
     C:\>cd xampp 
     C:\xampp>cd mysql 
     C:\xampp\mysql>cd bin 
     C:\xampp\mysql\bin>mysql -u root -h localhost -p 
     Enter password: 
     
     Welcome to the MariaDB monitor.  Commands end with ; or \g.  
     Your MariaDB connection id is 8  
     Server version: 10.4.13-MariaDB mariadb.org binary distribution  
                
     Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. 
            
     MariaDB [(none)]> 
     MariaDB [(none)]> show databases; 
     +--------------------+
     | Database           |
     +--------------------+
     | information_schema |
     | kamleen            |
     | mysql              |
     | performance_schema |
     | phpmyadmin         |
     | test               |
     +--------------------+
     6 rows in set (0.174 sec) 
                
     MariaDB [(none)]> use kamleen; 
     Database changed 
     MariaDB [kamleen]> show tables; 
     Empty set (0.012 sec) 
     
     MariaDB [kamleen]> create table user(  
     -> id int(250) auto_increment not null primary key,   
     -> name varchar(250) not null,  
     -> password varchar(250) not null  
     -> ); 
            
     Query OK, 0 rows affected (0.246 sec) 
     MariaDB [kamleen]> show tables; 
     
     +-------------------+
     | Tables_in_kamleen |
     +-------------------+
     | user              |
     +-------------------+
     1 row in set (0.001 sec)   
            
     MariaDB [kamleen]> select * from user;  
     Empty set (0.159 sec) 
     MariaDB [kamleen]> describe user; or desc user; 
     
     +----------+--------------+------+-----+---------+----------------+
     | Field    | Type         | Null | Key | Default | Extra          |
     +----------+--------------+------+-----+---------+----------------+
     | id       | int(250)     | NO   | PRI | NULL    | auto_increment |
     | name     | varchar(250) | NO   |     | NULL    |                |
     | password | varchar(250) | NO   |     | NULL    |                |
     +----------+--------------+------+-----+---------+----------------+
     3 rows in set (0.071 sec)
            
     MariaDB [kamleen]> INSERT INTO `user`(`name`, `password`) VALUES ("Mohd Kamleen","kamleen123");  
     Query OK, 1 row affected (0.049 sec) 
      MariaDB [kamleen]> select * from user; 
     
     +----+--------------+------------+
     | id | name         | password   |
     +----+--------------+------------+
     |  1 | Mohd Kamleen | kamleen123 |
     +----+--------------+------------+
     1 row in set (0.000 sec) 
            
     MariaDB [kamleen]> INSERT INTO `user`(`name`, `password`) VALUES (" Kamleen","123456");  
     Query OK, 1 row affected (0.049 sec) 
      MariaDB [kamleen]> select * from user; 
     
     +----+--------------+------------+
     | id | name         | password   |
     +----+--------------+------------+
     |  1 | Mohd Kamleen | kamleen123 |
     |  2 | Kamleen      | 123456     |
     +----+--------------+------------+
                2 rows in set (0.000 sec)
            
     MariaDB [kamleen]> UPDATE `user` SET `name`= "Mohd",`password`="mohd123" WHERE id = 1;  
     
     +----+--------------+------------+
     | id | name         | password   |
     +----+--------------+------------+
     |  1 | Mohd         | mohd123    |
     |  2 | Kamleen      | 123456     |
     +----+--------------+------------+
     2 rows in set (0.000 sec)
            
     MariaDB [kamleen]> drop table user;  
     Query OK, 0 rows affected (0.230 sec) 
     MariaDB [kamleen]> show tables;  
     Empty set (0.001 sec)