Home  >  Article  >  Database  >  linux mysql delete

linux mysql delete

WBOY
WBOYOriginal
2023-05-18 12:39:071442browse

In Linux systems, MySQL is a very commonly used database management system. If you use MySQL frequently, you will inevitably encounter situations where you need to delete a database or table. This article will introduce how to delete databases and tables in MySQL in Linux systems.

Delete MySQL database

In MySQL, deleting a database is very simple, just use the DROP DATABASE command. Assuming that the database to be deleted is named example, you can delete it with the following command:

DROP DATABASE example;

However, before deleting the database, you should back up the database to avoid accidentally deleting important data. Additionally, the delete operation will fail if the database is in use or there are clients connected to it.

Delete MySQL table

Similar to deleting a database, deleting a table is also very simple. Just use the DROP TABLE command. Assuming that the table to be deleted is named student, you can delete it with the following command:

DROP TABLE student;

Similarly, you should back up the data before deleting the table to avoid accidentally deleting important data.

Delete MySQL user

If you want to delete a user in MySQL, you can use the following steps:

  1. Log in to MySQL

Enter the following command in the terminal:

mysql -u root -p

Then enter your MySQL password to log in.

  1. View users

After logging in, run the following command in the MySQL command line:

SELECT user, host FROM mysql.user;

You will see the list of users in MySQL.

  1. Delete user

Assuming that the user you want to delete is foo, you can use the following command to delete it:

DROP USER 'foo'@'localhost';

If you only want to delete the account For some permissions, you can use the REVOKE statement, for example:

REVOKE INSERT ON *.* FROM 'foo'@'localhost';

The above command will revoke the INSERT permission of the foo account in all databases.

Summary

This article introduces how to delete MySQL databases, tables and users in Linux systems. Before deleting any objects, remember to back up your data. Also, be careful when dropping databases or tables as these operations cannot be undone.

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

Statement:
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
Previous article:mysql character escapeNext article:mysql character escape