Updated April 19, 2023
Introduction to MariaDB import SQL
MariaDB provides important SQL functionality to the user, in which we can import SQL files into the MariaDB server. In MariaDB we can use mysql command to import the sql file. Import sql is very good when a user handles the websites or blog. Sometimes databases are corrupted or we need to migrate to a different server or development environment. At that time we can use the import sql concept to achieve our desired goal. To perform import sql commands we must have a root access of the MariaDB server and it is suitable to run different commands. The import sql uses the mysql command to import the sql file into our desired location as per requirement.
Syntax
mysql –u specified user name – password of that user = database name < sql file name
Explanation
In above syntax we use mysql command to import the sql file in the MariaDB server; here specified user means actual user name with password of that user and database name is used to specify database data to import the sql file. Last part of the above syntax shows the actual sql file name that we need to import into the MariaDB server.
How to import SQL in MariaDB?
Creating backups of our website or any application is basically an important thing, because we don’t refer only to website files or applications but we also refer databases. Suppose an incident may occur such as system crush or data loss, so we must require the database when we update the technology, or data may be lost or we use a new environment. At that time we need a backup of all files as well as database files that sql file to migrate one environment to another development environment.
First we must have root access to import sql into the MariaDB server and we also require the database name, specified user name and password of that user to access the database.
Examples
Now let’s see different examples as follows.
First we login successfully into the MariaDB server by using private credentials such as user name and password.
After login we must need to create a new database by using the following syntax as follows.
Syntax
create database specified database name;
Explanation
In the above syntax we use the create database command to create a new database, here specified database name means actual database name that we need to create.
Example
create database sample;
Explanation
In the above example we use the create database statement to create a new database; here sample is a specified database name that we need to create. The end output of the above query we illustrate by using the following snapshot.
We can see the created database by using the following statement as follows.
show databases;
Explanation
In the above statement we use the show database statement to see all databases. The end output of the above query we illustrate by using the following snapshot.
Now we have a new database name as a sample and we also have all privileges to import sql files into the MariaDB server.
mysql –u root –p sample < demo1.sql
Explanation
In above example we use mysql command to import sql file into the MariaDB, here username is root as shown in above statement and p for password for that specified user, sample is database name that we already created and demo1.sql is a sql file that we need to import into the MariaDB server.
Using the above command, we can easily restore the newly created database into the MariaDB server. The above runs from the directory where sql file is stored otherwise we can provide an actual path. After the execution of the above statement we need to enter the user password. After inserting the password it imports the sql file into the sample database. The end output of the above query we illustrate by using the following snapshot.
If our sql file is located in a different location then we need to specify the path of the sql file.
We can also import sql files directly by using a dashboard and it is a very easy way to import the sql file.
Now see how we can provide the path to import the sql file as follows.
mysql - -user = 'root' - -password= '*******' sample < 'backup/demo1.sql'
Explanation
In the above example we use the mysql command to import the sql. In this example root is the username and password is used to specify the user, here password shows in star but actually it is in plaintext format. The sample is database name and after that we specified the path of the sql file that we need to import into the MariaDB server.
If sql file already exists into the MariaDB server then we cannot import sql again and again because data redundancy means it avoids the data duplication as well as it also minimizes the wastage of memory space.
It is always great to know how much simplest statements we use in MariaDB to import sql files. MariaDB statement is the minimum statement that is used in import that means a single statement allows us to do accurate action. There are many other aspects of import sql statement into MariaDB that we have not addressed here. We also have another way to import sql that is Perl modules that could be used to convert data files and this module is used to import the script. There are many ways to import sql into server.
Conclusion
We hope from this article you have understood about the MariaDB import sql. From this article we have learned the basic syntax of import sql and we also see different examples of import sql. From this article we learned how and when we use import sql.
Recommended Articles
We hope that this EDUCBA information on “MariaDB import SQL” was beneficial to you. You can view EDUCBA’s recommended articles for more information.