Showing posts with label mysql. Show all posts
Showing posts with label mysql. Show all posts

Friday, March 5, 2010

MySQL :: Create user

To create user
mysql> create user <username> identified by '<password>'

Then grant privileges
mysql> grant select, insert, update, delete, create, drop on <database_name>.* to '<username>'@'<mysql_host>';
or 
mysql> grant all privileges on <database_name>.* to '<username>'@'<mysql_host>';

MySQL :: Backup and Restore

To backup the database
$ mysqldump -u user -p backup.sql

or To backup specific tables from the database
$ mysqldump -u -p [table1 table2 ..] > backup.sql

or To backup set of databases
$ mysqldump -u user -p --databases [database_name database_name ..] >backup.sql

or To backup all databases
$ mysqldump -u user -p --all-databases > backup.sql

or To backup only the structure of the MySQL database, with no data
$ mysqldump -u user -p --no-data --databases [..] > backup.sql

or To zip the MySQL data
$ mysqldump -u user -p --all-databases | gzip > backup.sql.gz

-------------
To restore a database from backup.sql
$ mysql -u user -p < backup.sql

To restore all databases from backup.sql
$ mysql -u user -p < backup.sql

or Restore from a conpressed file
$ gzip | backup.sql.gz > mysql -u user -p