Manage MySQL Database in Linux


Some common commands are introduced for MySQL database management in Linux.

1. Connect to MySQL database server:
# mysql -h 'mysql-server' -u 'user' -p'password'

2. Display all databases:
# show databases;

3. Select a database:
# use 'db-name';

4. Display all tables in a database:
# show tables;

5. Display the schema of a table:
# describe 'table-name';

6. Create a new database:
# CREATE DATABASE 'db-name';

7. Create a new table:
# CREATE TABLE ('attribute-1 type', 'attribute-2 type', ...);

8. Delete a table:
# DROP TABLE 'table-name';

9. Delete a database:
# DROP DATABASE 'db-name';

10. Insert a record into a table:
# INSERT INTO 'table-name' VALUES ('attribute-1', 'attribute-2', ...);

11. Change the schema of a table:
# ALTER TABLE 'table-name' ADD/DROP 'attribute' 'type' 'specification';

12. Grant to a database to a user:
# GRANT ALL ON 'db-name'.* TO 'user'@'mysql-server';

13. Exit the MySQL server:
# exit

Free Web Hosting