Linux Secrets

I’m in the process of moving, optimizing, and finding more efficient and space saving ways to use MySQL. This will document some of the tricks I am learning for my future reference.

How to see how much diskspace a database is taking up

 SELECT table_schema AS "database", SUM(data_length + index_length) / 1024 / 1024 AS "Size (MB)" FROM information_schema.TABLES GROUP BY table_schema;

Dump mysql database to file and transfer it to another server

mysqldump -u username -p database_to_backup > backup_name.sql

Move the backup_name.sql file to the server you want to have the database on.
then login to your mysql database and add a new database.

mysql -u username -p
CREATE DATABASE database_name;
mysql -u username -p database_name < backup_name.sql

make a new user with all privileges

CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';

See what storage engine is used on mysql tables

FROM information_schema.TABLES
ALTER TABLE auction ENGINE = rocksdb;

Get Disk space used by directory

du -hs /path/to/directory

Mount ramdisk

mount -t tmpfs -o size=512m tmpfs /mnt/ramdisk

See what files are being written to by a process

 lsof -p PID

Compress directory into a tar file

tar -zcvf archive-name.tar.gz directory-name


adduser git
cd /srv/git
mkdir project.git
cd project.git
git init --bare
Then on the other computer you want to do code dev on:
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/srv/git/project.git
git push origin master
Then if you want to pull the changes on another commputer and upload:
git clone git@gitserver:/srv/git/project.git
... changes ...
git push origin master
If you want to check out changes upstream that another person uploaded:
git fetch
git merge