IMPORTANT:
Some of the content here is a personal summary/abbreviation of contents on the Offical MySQL Guide. Feel free to refer to the official site if you think some of the sections written here are not clear.
MySQL Intro
The MySQL client program can be used to create and use a simple database. MySQL (sometimes referred to as the “terminal monitor” or just “monitor”) is an interactive program that enables you to connect to a MySQL server, run queries, and view the results.
The MySQL server package will install the MySQL database server which you can interact with using a MySQL client. You can use the MySQL client to send commands to any MySQL server; on a remote computer or your own.
The MySQL server is used to persist the data and provide a query interface for it (SQL). The MySQL clients purpose is to allow you to use that query interface.
On how to setup your MySQL Server, please refer to here
Connecting to a MySQL Server
If you have installed the MySQL server on Docker using the guide here, then you should be already connected to your local SQL server. If not, try to run (assuming you have the container running):
1
docker exec -it <yourSQLServerName> mysql -u root -p
This will prompt to enter the password.
If you entered successfully, you will see:
1
mysql>
If you want to connect to a remote SQL server, then you need to specify a
host
name. Contact your administrator to find out what connection parameters you should use to connect (that is, whathost
,user
name, andpassword
to use). Then, you would run:1
2shell> mysql -h <hostName> -u <userName> -p
Enter password: <yourPasswordHere>To disconnect from that SQL server, simply run:
1
QUIT
Basic Queries in MySQL Client
Make sure that you are connected to the server, as discussed in the previous section. Doing so does not in itself select any database to work with, but that is okay. There are still several queries you can do to have a basic sense of how MySQL works: