Appearance
Server and Client
After installing MySQL, you have both the MySQL Server and the MySQL Client program. The MySQL Client is a command-line tool that allows you to log into MySQL, input SQL statements, and execute them.
Connecting to MySQL
To connect to the MySQL Server, open the command prompt and enter:
bash
mysql -u root -p
You'll be prompted for the MySQL root password. Once entered correctly, you'll be connected, and the prompt will change to mysql>
.
Example Output
plaintext
C:\> mysql -u root -p
Enter password: ******
Server version: 5.7
Type 'help;' or '\h' for help.
mysql>
To disconnect from the MySQL Server, type exit
.
MySQL Executables
- The MySQL Client executable is
mysql
. - The MySQL Server executable is
mysqld
.
Communication Flow
The relationship between the MySQL Client and Server is as follows:
┌──────────────┐ SQL ┌──────────────┐
│ MySQL Client │───────▶│ MySQL Server │
└──────────────┘ TCP └──────────────┘
SQL statements entered in the MySQL Client are sent to the MySQL Server over TCP, typically on port 3306 (localhost: 127.0.0.1:3306).
Remote Connection
You can also use the MySQL Client to connect to a remote MySQL Server. For example, to connect to a server with IP address 10.0.1.99
, use:
bash
mysql -h 10.0.1.99 -u root -p
Summary
The command-line program mysql
is the MySQL Client, while the actual MySQL server program mysqld
runs in the background.