MySQL is an open source relational database management system(RDBMS), which has been popular for more than 20 years. It is widely used in web server solutions and standalone applications on Linux systems. This article will provide an overview of the most commonly used MySQL utilities, including mysql and mysqladmin, and provide some examples of how to use them. It's worth noting that the explanations in this article also apply to MariaDB, a popular fork of MySQL created by the original developers out of concern that MySQL might not remain open source and intended to remain highly compatible with MySQL.
When you install MySQL, two packages are provided: mysql-server, which contains the server and all the utilities to connect to the server, and mysql-client, which contains only Utility for connecting to servers in other locations. No matter which package you choose, there will be several commands starting with "mysql".
The mysql command is the command line client and main binary for connecting to a MySQL server. It provides a shell where we can interact with MySQL or MariaDB server. Most Linux distributions require you to run these utilities as root.
The mysql command is the command line client and main binary used to connect to the MySQL server. It provides a shell through which we can interact with MySQL or MariaDB servers. Most Linux distributions require you to run these utilities as root .
$ sudo mysql -u root Welcome to the MySQL monitor. Commands end with ; or \g. ... mysql>
Using this command, we can access the shell in interactive mode. We can continuously enter SQL statements to interact with the database, using the same connection.
For example, we can query the system database to get all users in the system −
mysql> select host, user from mysql.user; +-----------+------------------+ | host | user | +-----------+------------------+ | % | root | ... +-----------+------------------+ 6 rows in set (0.00 sec)
We can also use MySQL specific statements such as USE and SHOW TABLES −
mysql> SHOW TABLES; +---------------------------+ | Tables_in_mysql | +---------------------------+ | columns_priv | ... +---------------------------+ 33 rows in set (0.01 sec)
mysqladmin is a tool used to perform administrative tasks on the server. It is a non-interactive client that prompts for the commands and operations we want to perform. For example, we can use mysqladmin to create and delete databases −
$ sudo mysqladmin create the_database $ $ sudo mysqladmin drop the_database ... Do you really want to drop the 'the_database' database [y/N] y Database "the_database" dropped $
In this section, we will explore some additional tools for managing and maintaining MySQL databases. These tools include "mysqldump", "mysqlrepair" and "mysqlimport". mysqldump is a powerful database backup tool that can be used to back up or transfer a single database or a group of databases to another SQL server. "mysqlrepair" is a utility tool for repairing damaged tables in MySQL databases. It can be used to repair MyISAM and InnoDB tables. Finally, "mysqlimport" is a tool for importing data from text files into MySQL tables, where each row represents a new record and each field is separated by tabs.
The Chinese translation ofmysqldump is a utility tool used to create database backup. It can be used to download a database or a set of databases for backup or transfer to another SQL server.
$ mysqldump -u root -p db_name > db_name.sql
mysqlrepair is used to repair damaged tables in the MySQL database. It can be used to repair MyISAM and InnoDB tables.
$ mysqlrepair -u root -p db_name table_name
mysqlimport Used to import data from text files into MySQL tables. The text file must be in a specific format, with each line representing a new record and each field separated by tabs.
$ mysqlimport -u root -p db_name table_name.txt
In summary, MySQL is a powerful and widely used relational database management system that is ideal for both small and large applications. The MySQL client and related tools on Linux allow you to connect to a MySQL server, create and manage databases and tables, and manipulate data. This article provides an overview of how to use the MySQL client and related tools on Linux, including sample commands to connect to a MySQL server, create and manage databases and tables, and manipulate data, as well as additional instructions for secure backup and repair. tool. Understanding the differences between these tools will help you use them more effectively and efficiently.
The above is the detailed content of How to use mysql client and related tools in Linux. For more information, please follow other related articles on the PHP Chinese website!