Skip to content

Instantly share code, notes, and snippets.

@varunpalekar
Last active May 23, 2017 08:28
Show Gist options
  • Save varunpalekar/4e80fece2b256ba75b43da8b4812c862 to your computer and use it in GitHub Desktop.
Save varunpalekar/4e80fece2b256ba75b43da8b4812c862 to your computer and use it in GitHub Desktop.
mysql

Create database dump

mysqldump -h mysqlhost --port 3306 -u reporting -p database_name | gzip > database_name_$(date '+%y-%m-%d').gz

Restore mysql dump to database

mysql -u <user> -p -h mysqlhost [database] < db_backup.dump

See size of all Database in MySQL

SELECT table_schema "Database Name",
    sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
    sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ; 

Mysql Database copy from one table to another

 mysqldump -h data.base.host --password=pass -u user database1 \
| mysql -h data.base.host --password=pass -u user database2

Create user and database

create database temp_data;
grant all privileges on temp_data.* to 'temp_data_user'@'localhost' identified by "password";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment