Skip to content

Commit

Permalink
docs: Add commands for MySQL
Browse files Browse the repository at this point in the history
  • Loading branch information
VishwajeetVT committed Dec 12, 2024
1 parent db355a7 commit 8bbcc04
Showing 1 changed file with 77 additions and 1 deletion.
78 changes: 77 additions & 1 deletion docs/sql/MySQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,80 @@ web technologies like PHP and frameworks such as Spring Boot for backend develop
- Create user: `CREATE USER 'username'@'host' IDENTIFED BY 'password';`
- Grant Privileges: `GRANT ALL PRIVILEGES ON database_name TO 'username'@'host';`
- Revoke Privileges: `REVOKE ALL PRIVIKEGES ON database_name FROM 'username'@'host';`
- Flush Privileges (apply changes): `FLUSH PRIVILEGES;`
- Flush Privileges (apply changes): `FLUSH PRIVILEGES;`

4. Table Operations:
- Create Table:
```sql
CREATE TABLE users(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(40),
email VARCHAR(40) UNIQUE
);
```
- Drop Table:
```DROP TABLE users;```
- Rename a Table:
```RENAME TABLE old_table TO new_table;```
- Add a Column:
```ALTER TABLE users ADD COLUMN age INT;```
- Drop a Column:
```ALTER TABLE DROP COLUMN age;```

5. Query Operations:
- Insert the Data:
```INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');```
- Select Data:
``` SELECT * FROM users;```
- Update a Data:
```UPDATE users SET name = 'Jane Doe' WHERE id = 1;```
- Delete a Data:
```DELETE FROM users WHERE id = 1;```

6. Filtering and Sorting:
- Filter rows:
```SELECT * FROM users WHERE age > 25;```
- Sort Rows:
```SELECT * FROM users ORDER BY names ASC;```
- Limit Rows:
```SELECT * FROM users LIMIT 10 OFFSET 5;```

7. Aggregation and Grouping:
- Count Rows:
```SELECT COUNT(*) FROM users;```
- Group Data:
```SELECT age, COUNT(*) FROM uses GROUP BY age;```
- Find Maximum and Minimum:
```SELECT MAX(age), MIN(age) FROM users;```

8. Index Management:
- Create an Index:
```CREATE INDEX idx_name ON users(name);```
- Drop an Index:
```DROP INDEX idx_name ON users;```

9. Transaction Management:
- Begin Transaction:
```START TRANSACTION;```
- Commit Transaction:
```COMMIT;```
- Rollback Transaction:
```ROLLBACK;```

10. Miscellaneous Commands
- Show Current user:
``` SELECT USER();```
- Show Current Database:
``` SELECT DATABASE();```
- Show Server Version:
```SELECT VERSION();```
- Show Running process:
```SHOW PROCESSLIST;```
- Kill a Process:
```KILL PROCESS_ID;```

11. Import and Export Data
- Import Data:
``` mysql -u username -p database_name < dumpfile.sql ```
- Export Data:
``` mysqldump -u username -p database_name > dumpfile.sql ```

0 comments on commit 8bbcc04

Please sign in to comment.