Skip to content

Instantly share code, notes, and snippets.

@rezigned
Last active December 10, 2015 03:08
Show Gist options
  • Save rezigned/4372017 to your computer and use it in GitHub Desktop.
Save rezigned/4372017 to your computer and use it in GitHub Desktop.
MySQL commands

How to export data

# mysqldump -u {username} -p {database} > {filename}

mysqldump -u john -p mydb > mydb-dump.sql

How to export specific tables

# mysqldump -u {username} -p {database} {table1} {table2..N} > {filename}

mysqldump -u john -p mydb table1 table2 > mydb-dump.sql

How to import data

# mysql -u {username} -p {database} < {filename}

mysql -u john -p mydb < mydb-dump.sql 

How to reset root password

# Stop mysql service first
sudo service mysql stop

# Start mysql in safe mode 
sudo mysqld_safe --skip-grant-tables &

# Login to mysql
mysql -u root

# Change password
mysql> UPDATE mysql.user SET Password=PASSWORD('new-pass-word') WHERE User='root';
mysql> FLUSH PRIVILEGES;

# Stop mysql server
sudo service mysql stop
References

http://dev.mysql.com/doc/refman/5.0/en/resetting-permissions.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment