Requirements Description :
How do I execute a SQL script file on the operating system by logging in to the MySQL database via the MySQL client?
Operation Process :
1. Writing a test script file
Cat secount.sql Use test01 Select Count (*) from ts051;
2. Log in to the MySQL database
[Email protected] scripts]$ Mysql-uroot-Penter Password:welcome to the MySQL Monitor. Commands End With; or \g.your MySQL connectionIDIs -Server Version:5.5. $-log MySQL Community Server (GPL) Copyright (c) -, -, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or Itsaffiliates. Other names trademarks of their respectiveowners. Type'Help ;'Or'\h' forHelp. Type'\c'ToClearThe current input statement.mysql>
3. Execute scripts on the system via the source command or the \. Command
Mysql>Source Secount.sqlDatabasechanged+----------+| Count(*)|+----------+| 557107 |+----------+1Rowinch Set(0.24sec) MySQL> \. Secount.sqlDatabasechanged+----------+| Count(*)|+----------+| 557107 |+----------+1Rowinch Set(0.27sec) MySQL>
or use the absolute path of the script :
Mysql>Source/Home/Mysql/Workspace/Scripts/Secount.sqlDatabasechanged+----------+| Count(*)|+----------+| 557107 |+----------+1Rowinch Set(0.23sec) MySQL>\./Home/Mysql/Workspace/Scripts/Secount.sqlDatabasechanged+----------+| Count(*)|+----------+| 557107 |+----------+1Rowinch Set(0.23sec) MySQL>
Note: Through the above way, source or \. Can execute SQL statements in SQL scripts.
Document bedstead Time: March 20, 2018 13:03:24
MySQL database, how to execute SQL scripts on the operating system after logging in to MySQL?