Commandes de base
Check server status:
sudo /etc/init.d/mysql status
Start or stop the server:
sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql restartConnect to the databse:
mysql -u root -p
Then type the password.
The same can be done in order to connect to a specific database:
mysql -u root -p databaseName
Create a database:
CREATE DATABASE databaseName;
List all databases
SHOW DATABASES;
Delete a database
DROP DATABASE databaseName;
Use a database:
use databaseName;
List all tables for the current database:
SHOW TABLES;
Show table structure:
DESCRIBE tableName;
Rename a table:
ALTER TABLE tableName RENAME AS newTableName;
Quit the client:
quit;
Backup & restore
In order to backup a database (named myBase), type:
mysqldump -u root -p myBase > myBase_backup.sql
All the data can be found in the file « myBase_backup.sql ».
In order to backup only a table (named myTable) from the database (named myBase):
mysqldump -u root -p myBase myTable > my_table.sql
To restore the backup, type:
mysql -u root -p myBase < myBase_backup.sql
Then type the password.
Another way to perform a backup is to archive the folder:
/var/lib/mysql/
where are located all databases.
To optimise the database:
mysqlcheck -u root -p --check --databases myBase
mysqlcheck -u root -p --optimize --databases myBase
mysqlcheck -u root -p --analyze --databases myBase