XAMPP MySQL Command Line

We will learn how to run MySQL on the command line with the XAMPP server. We will also learn how to create and import a database in an existing database from the command line.
Use MySQL Command Line With XAMPP
Several times around the MySQL community, a question arises about how people can access the MySQL command line with the XAMPP server on the Windows operating system. First, we have to download and install XAMPP; visit here for the installation guide.
After installation is completed, we will run XAMPP and start Apache and MySQL, and we will go on the browser and hit this http://localhost/phpmyadmin/index.php
URL. This will show an interactive interface; it can be used for writing SQL queries and execute easily.
To access MySQL with XAMPP from the command line, we will open any terminal and change the directory from the user to the bin
directory wherever our XAMPP
server is located. In our case, we will use the following command because our XAMPP is located in this location.
cd /d E:\XAMPP\mysql\bin
Now we can start writing a command that will connect us with MySQL.
mysql -u root -p -h 127.0.0.1
Here, -u
stands for the user, and our user is root
because we are using the default user; this could be changed in your case. -p
stands for the password, and in our case, the password is null that is why we are not using any password in front of this keyword, -h
stands for host and we are using localhost
.
Then we will hit Enter, and it will tell us to enter the password; remember, we said when your password is null, continue this by pressing the Enter key.
Now we are connected to the MariaDB.
Import Database in an Existing Database
In the above section, we have learned how to run MySQL on the database on the command line or terminal with the XAMPP server. And, now we will look at how to create and import a database in MySQL from the command line interface.
First, we will create a database and create a database; we will get access to MySQL on the command line. We already have learned to get access to MySQL on a terminal; inside MySQL, we will execute the following command.
create database example_Db;
We have created a database called example_Db
, and the following output proves that a command executed successfully and created a database.
Query OK, 1 row affected (0.045 sec)
A few beginners make a horrible mistake and get an error when they import a database on an existing database. The mistake is noticed that they execute the following command inside the MySQL database and get an unexpected error.
We have to be careful while executing the following command. We have to exit MySQL using the exit
command and execute this command.
After the <
sign, we put the path of the database file. You can define your password in front of -p
if you set your password before.
mysql -u root -p example_Db < E:\example\example_Db.sql
Now we will hit http://localhost/phpmyadmin/index.php
on the browser and follow these steps: Databases
> example_Db
> user_details
> Structure
.
Visit here for more answers.
Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.
LinkedIn