Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Mysql Commands

Uploaded by

komoireashiraf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Mysql Commands

Uploaded by

komoireashiraf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MySQL Command Line Commands

Starting and Exiting MySQL

1. Log into MySQL:

mysql -u username -p

After entering this command, you'll be prompted for your MySQL password.

2. Exit MySQL:

exit;

or

quit;

Basic Commands

3. Show all databases:

SHOW DATABASES;

4. Use a specific database:

USE database_name;

5. Show all tables in the selected database:

SHOW TABLES;

6. Describe table structure:

DESCRIBE table_name;

or

DESC table_name;
7. Create a new database:

CREATE DATABASE database_name;

8. Drop (delete) a database:

DROP DATABASE database_name;

Table Operations

9. Create a new table:

CREATE TABLE table_name (

column1_name datatype constraints,

column2_name datatype constraints,

...

);

10. Drop a table (delete):

DROP TABLE table_name;

11. Show table structure (columns, types, etc.):

SHOW COLUMNS FROM table_name;

12. Insert data into a table:

INSERT INTO table_name (column1, column2, ...)

VALUES (value1, value2, ...);

13. Select data from a table:

SELECT * FROM table_name;


or

SELECT column1, column2 FROM table_name;

14. Update data in a table:

UPDATE table_name

SET column1 = value1, column2 = value2

WHERE condition;

15. Delete data from a table:

DELETE FROM table_name

WHERE condition;

User Management

16. Create a new user:

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

17. Grant privileges to a user:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'host';

18. Show current user:

SELECT USER();

19. Show all users:

SELECT user FROM mysql.user;

20. Drop (delete) a user:

DROP USER 'username'@'host';

You might also like