Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

MySQL Connection

MySQL Connection

After installing MySQL, you can connect to the MySQL server in the following ways:

Common MySQL graphical management tools:


Connect Using the MySQL Binary

You can use the MySQL binary to enter the mysql command prompt to connect to the MySQL database, in the following format:

mysql -u your_username -p

Parameter Description:

Specify host and port to connect (for remote connections):



mysql -h 主机名或IP地址 -P 端口号 -u 用户名 -p

For example:



mysql -h 127.0.0.1 -P 3306 -u root -p

Example

The following is a simple example of connecting to the mysql server from the command line:



[root@host]# mysql -u root -p

Enter password:******

Enter the password as prompted and press the Enter key.

After a successful login, the mysql> command prompt window appears, where you can execute any SQL statement.

After executing the above command, the successful login output is as follows:



Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 2854760 to server version: 5.0.9



Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

In the above example, we used the root user to log in to the MySQL server; of course, you can also log in with other MySQL users.

If a user has sufficient permissions, any user can perform SQL operations in the MySQL command prompt window.

After successfully connecting to MySQL, you can execute SQL queries directly on the command line.

List all available databases:

SHOW DATABASES;

Select the database to use:



USE your_database;

List all tables in the selected database:

SHOW TABLES;

To exit the mysql> command prompt, you can use the exit command, as shown below:



mysql> EXIT;

Bye

Or use:

mysql> QUIT;

Or press Ctrl + D (on Unix/Linux systems).


Database Management Tools

1. DBeaver

DBeaver is a free, open-source, cross-platform database management tool.

DBeaver supports a variety of database systems, including MySQL, PostgreSQL, MariaDB, SQLite, Oracle, DB2, SQL Server, Sybase, MS Access, Teradata, Firebird, Derby, and more.

Download address:https://dbeaver.io/download/

2. DbGate

DbGate is a cross-platform database management tool that supports multiple database systems, including MySQL, PostgreSQL, Microsoft SQL Server, SQLite, MongoDB, and more.

DbGate runs on Windows, Linux, and Mac operating systems, giving users cross-platform flexibility.

DbGate is not just a local application; it can also run as a web application, allowing users to easily access and manage databases through a browser.

Download address:https://dbgate.org/download/