HOWTO · MySQL
How to Access MySQL Command Line With XAMPP
Connect to XAMPP's MySQL-compatible server from the command line, create a target database, and import an SQL file into it.
On this page
To access MySQL from XAMPP, start its database service, open a terminal, and run the bundled mysql client with your connection details. Then create a target database and load your .sql dump into it. XAMPP can supply MariaDB as its MySQL-compatible server, so the client prompt may say MariaDB.
The commands below are unexecuted, installation-dependent instructions. They require a local XAMPP installation and a running database service; no execution output is supplied here.
Access MySQL from the XAMPP Command Line
Start the database service using your platform’s XAMPP control panel or manager. On Windows, click Start beside MySQL, then open Shell or Command Prompt. Apache is needed only for the optional phpMyAdmin browser check, not for a terminal connection.
Locate the bundled client. These are example installation paths; adjust them to match your installation:
| Platform | Client directory | Change directory | Run the client |
|---|---|---|---|
| Windows Command Prompt | C:\xampp\mysql\bin |
cd /d "C:\xampp\mysql\bin" |
mysql.exe |
| macOS native installation | /Applications/XAMPP/xamppfiles/bin |
cd /Applications/XAMPP/xamppfiles/bin |
./mysql |
| Linux | /opt/lampp/bin |
cd /opt/lampp/bin |
./mysql |
From the Windows client directory, enter mysql.exe -u root -p -h 127.0.0.1 -P 3306. On macOS or Linux, use ./mysql in place of mysql.exe. Replace root and 3306 with your configured account and port.
Here, -u selects the user, -p requests a password prompt, -h selects the host, and uppercase -P selects the port. Enter the account’s password when prompted. Press Enter without typing a password only if you know that account has no password. Avoid putting passwords directly in commands, where they can enter shell history.
127.0.0.1 selects a local TCP connection. Using localhost, or omitting -h, can select a local socket on Unix systems; these connection methods are not always interchangeable. Keep the same host and port throughout this procedure.
If the client is not found, check its installation path or add that directory to PATH. A connection failure calls for checking the service and port; an access-denied message calls for checking the account, password, and permitted connection host. After connecting, enter SQL at the client prompt, without copying the prompt itself.
Create a Database in MySQL
At the database client prompt, enter CREATE DATABASE example_Db;, then USE example_Db;. The first statement creates the database; the second selects it for subsequent statements in that session. End each SQL statement with a semicolon.
The client normally acknowledges successful creation with Query OK; timing and formatting vary. Confirm the selection with SELECT DATABASE();, which returns the selected database name. If example_Db already exists, select it rather than trying to create it again. Creation requires the account to have the appropriate privilege. Keep the database name’s capitalization consistent.
Import an SQL File into an Existing Database
Importing runs the statements in an SQL file against a target database. Review the dump first: it can contain destructive statements, and its own USE statements can change the target. Back up any existing data you need to retain.
Enter exit to leave the database client. In Windows Command Prompt, run mysql.exe -u root -p -h 127.0.0.1 -P 3306 example_Db < "E:\example\example_Db.sql". Replace the quoted path with your actual dump file. This uses the same account, host, and port as the connection above.
On macOS or Linux, from the bundled client directory, use ./mysql -u root -p -h 127.0.0.1 -P 3306 example_Db < "/path/to/example_Db.sql". Windows PowerShell does not support this < syntax; use Command Prompt for the Windows example.
The shell’s < operator supplies the file to the client. Do not enter this command at the MySQL or MariaDB prompt. For both commands shown above, example_Db must already exist: each supplies it as the client’s initial database. If it does not exist, connection initialization fails before any CREATE DATABASE or USE statement in the dump can execute. To import a dump that creates and selects its own database, omit the positional example_Db argument from the import command and ensure the account has the privileges required by the dump’s statements. File-not-found errors require correcting the local dump path; unknown-database errors require creating or correcting the target.
After import, reconnect with the same connection command, enter USE example_Db;, and run SHOW TABLES;. Check expected tables and data against the dump. If it defines user_details, inspect it with DESCRIBE user_details; and SELECT COUNT(*) FROM user_details;; otherwise substitute a table it actually defines. A return to the shell alone does not establish that all intended data loaded.
For optional visual inspection, start Apache, open http://localhost/phpmyadmin/ using your configured web-server port, select example_Db, and inspect the expected table’s Structure or Browse view.