Home > Database > Mysql Tutorial > body text

How to install mysql client on linux

PHPz
Release: 2023-04-21 14:01:20
Original
6432 people have browsed it

MySQL is a widely used relational database management system. Its client software is a program used to access and manage the MySQL server, called the MySQL client. Using the MySQL client on a Linux system can help users perform various operations under the command line, such as creating, deleting, querying, updating, and managing databases. In this article, we will explain how to install and use the MySQL client on Linux.

Install MySQL client

Before installing the MySQL client on Linux, we need to make sure we have installed the MySQL server. We need to install MySQL server if we haven't already. Next, we will demonstrate how to install the MySQL client on an Ubuntu system.

Open a terminal and update the package list

$ sudo apt-get update

Install MySQL client

$ sudo apt-get install mysql-client

Waiting for the download and installation of the software package. This may take some time. Once completed, we can start the MySQL client by entering the mysql command in the terminal.

$ mysql -u root -p

Among them, the -u option is used to specify the MySQL user name, and the -p option instructs the MySQL client to subsequently require a password. After entering the above command, we need to enter the root user password of the MySQL server to log in to the MySQL client.

Using MySQL Client

After logging in to the MySQL client, we can start using it to manage the MySQL server. Here are a few examples of performing common tasks in the MySQL client:

Create a new database:

mysql> CREATE DATABASE my_database;

Query all databases:

mysql> SHOW DATABASES;

Drop a database:

mysql> DROP DATABASE my_database;

Create a new table:

mysql> CREATE TABLE my_table (id INT, name VARCHAR(50));

Query a table:

mysql> SELECT * FROM my_table;

Update a table:

mysql> UPDATE my_table SET name='new_name' WHERE id=1;

Delete a table:

mysql> DROP TABLE my_table;

Exit MySQL Client:

mysql> quit;

Summary

In this article, we introduced how to install and use the MySQL client on a Linux system. MySQL client is a very practical tool for managing MySQL servers. Before installing and using the MySQL client, we need to make sure we have installed the MySQL server. In Linux systems, we can use the apt-get command to install the MySQL client. After the installation is complete, we can use the mysql command in the terminal to start the MySQL client and use various commands to manage the MySQL server.

The above is the detailed content of How to install mysql client on linux. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template