Introduction:Use of the MySQL client can be improved at times by using script files. These files are normal text files with a .sql file extension. They can provide speed, reuse, and edibility improvements over the command line mysql client. Show Requirements:Procedure:Script files contain any MySQL client-readable commands that could be directly invoked on the interactive client. Each statement can be separated by a line break, and terminated by semicolons (;). Script files can be used in two different ways. Within the interactive mysql client, script files can be called as any other MySQL client command would be invoked: SOURCE filename.sql; This script file was invoked using its relative path. For instance, if you invoked the mysql command line client from C:/Users/User/Desktop and the .sql file is located at C:/Users/User/Desktop, then the path is unnecessary, only the file name is needed. However, if you invoked the mysql client from C:/Users/User, you could locate the file by either using the relative path, or the full path: SOURCE Desktop/filename.sql; or the full path: SOURCE C:/Users/User/Desktop/filename.sql; The second approach to invoking the script file, is to invoke it from the commandine, using the mysql client but before the client is initiated with a database connection: mysql -u root -p < C:\Users\User\Desktop\filename.sql If the script file contains errors, the statements following the error will not be executed. To continue after the error, you can add either of the following to force continued execution: mysql -u root -p < C:\Users\User\Desktop\filename.sql -f or mysql -u root -p < C:\Users\User\Desktop\filename.sql --force Within the script file itself, you can include any MySQL client-interpretable statements, such as: SELECT * FROM TABLENAME; You can also include SOURCE commands inside the script file. This will call other script files for execution. Adding SOURCE calls to the script file performing the call should be avoided. Do you really need the entire database to be restored? If you don't, my 2c: You can extract specific tables to do your restore on "chunks". Something like this:
I did it once and it took like 10 minutes to extract the table I needed - my full restore took 13~14 hours, with a 35GB (gziped) dump. The Anyways, to restore the 35GB I used an AWS EC2
machine (c3.8xlarge), installed Percona via yum (Centos) and just added/changed the following lines on
I think the numbers are way too high, but worked for my setup. When you need to run a saved You can run SQL scripts with or without opening a connection to the MySQL server. First, let’s see how to run SQL files while connected to a MySQL server Run SQL file while connected to the serverFor example, suppose you have a file named
The script will select a database named To run SQL files from the terminal, you can use the First, you need to connect to your MySQL database server using the Next, enter
the password for your Once inside, use the
The path MySQL will print the output in the command line if any. Here’s an example of running the
And that’s how you run SQL files from the terminal while being connected to MySQL database server. Let’s see how you can run SQL files without having to connect to the server next. Run SQL file while not connected to the serverThe You only need to provide
the
For example, here’s how to run the same
Once again, the command line client will ask for a password to run the operation. Here’s an example of the output in my terminal:
As you can see from the output above, the But you won’t see any difference if your SQL script contains Also, if you have a
The above example works because the Without the You have learned how to run SQL files or scripts from the terminal. Great job! 👍 How do I run a large SQL file in MySQL?Save the file and run this command in mysql: set global innodb_fast_shutdown = 0. you can see the new configuration with @@ followed by command in mysql: select @@innodb_buffer_pool_size; ... . Restart mysql: service mysql restart.. Restore your database state: mysql -u username -p database_name < /path/to/file.sql.. How do I run a large SQL script?On the Database menu, click Execute Large Script. In Connection, select a connection to a required database server against which you want to execute your script. In Database, select a required database from the drop-down list. In File name, specify the path to the script you want to execute.
How to import large SQL file in MySQL with command line?Show activity on this post.. Open the MySQL command line.. Type the path of your mysql bin directory and press Enter.. Paste your SQL file inside the bin folder of mysql server.. Create a database in MySQL.. Use that particular database where you want to import the SQL file.. Type source databasefilename.sql and Enter.. How to run SQL script in MySQL command line?use the MySQL command line client: mysql -h hostname -u user database < path/to/test. sql. Install the MySQL GUI tools and open your SQL file, then execute it. Use phpmysql if the database is available via your webserver.
|