Third, retrieve data from the products table: select * from products Code language: SQL (Structured Query Language) ( sql ) Second, show all the tables in the sales database: + -+ġ row in set ( 0.00 sec) Code language: SQL (Structured Query Language) ( sql ) To verify the execution you can follow these steps:įirst, connect to the sales database: mysql -u root -p -D sales Code language: SQL (Structured Query Language) ( sql ) To execute the script.sql file, you use the following command: mysql -u root -p sales < c:/temp/script.sql Code language: SQL (Structured Query Language) ( sql ) ( 'Gaming Console XYZ', 399.99) Code language: SQL (Structured Query Language) ( sql ) INSERT INTO products (product_name, price) Third, exit the mysql: exit Code language: SQL (Structured Query Language) ( sql )Ĭreate a new file called script.sql with the following code and save it to the c:\temp directory: CREATE TABLE products( Second, create a new database called sales: CREATE DATABASE sales Code language: SQL (Structured Query Language) ( sql ) We’ll create a new database called sales for the demonstration.įirst, connect to the MySQL server: mysql -u root -p Code language: SQL (Structured Query Language) ( sql ) After providing the password, you press the Enter key to execute. The command will prompt you to enter a password for the username. In this command, you replace the username with your MySQL username, database_name with the target database and path/to/your/sqlfile.sql with the actual path to your SQL file. Second, run the following command: mysql -u username -p database_name < path/to/your/sqlfile.sql Code language: SQL (Structured Query Language) ( sql ) Executing a SQL file using MySQL command-line interfaceįirst, open the Command Prompt on Windows or the Terminal on macOS or Linux. MySQL offers serval ways to execute an SQL file. Running an SQL file in MySQL is an essential skill for database administrators and developers. (Not using Oracle, I can't test this code.Summary: in this tutorial, you will learn various ways to execute an SQL file in MySQL using the mysql command line interface, the source command, and the MySQL Workbench. || TO_CLOB('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx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xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') Running the file ins.sql will look like: SQL> select /*insert*/* from t The following code will create a table with a CLOB and export to to the file Putting the comment /*insert*/ in the script will cause SQL Developer to
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |