Difference between revisions of "Mysql notes"
 (→Backup a database)  | 
				 (→Backup a database)  | 
				||
| (One intermediate revision by the same user not shown) | |||
| Line 10: | Line 10: | ||
 mysqldump -u root -p [databasename] > [backupfile.sql]  | 
   mysqldump -u root -p [databasename] > [backupfile.sql]  | 
||
== Restore a database ==  | 
|||
 mysql -u root -p [databasename] < [backupfile.sql]  | 
|||
== Change a root password ==  | 
  == Change a root password ==  | 
||
| Line 24: | Line 26: | ||
  sudo /etc/init.d/mysql stop  | 
    sudo /etc/init.d/mysql stop  | 
||
  sudo mysqld --skip-grant-tables  | 
    sudo mysqld --skip-grant-tables  | 
||
  mysql -u root   | 
    mysql -u root   | 
||
  mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';  | 
    mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';  | 
||
  mysql> FLUSH PRIVILEGES;   | 
    mysql> FLUSH PRIVILEGES;   | 
||
  mysql> exit  | 
    mysql> exit  | 
||
  sudo mysqladmin shutdown -u root  | 
    sudo mysqladmin shutdown -u root -p  | 
||
  sudo /etc/init.d/mysql start  | 
    sudo /etc/init.d/mysql start  | 
||
Latest revision as of 14:22, 3 June 2011
Contents
Links
Backup a database
You may want to log in mysql and do "show databases;" to see which to backup, then do it like this.
mysqldump -u root -p [databasename] > [backupfile.sql]
Restore a database
mysql -u root -p [databasename] < [backupfile.sql]
Change a root password
Change an existing Mysql root password like this:
mysqladmin -u root -p'oldpassword' password 'newpassword'
Lost MySQL password?
By example: recreated mysql passwords for the wikiuser and mysql-root. You can reset root password - stop mysql and start the daemon like this:
- reset mysql root password
 
 sudo /etc/init.d/mysql stop
 sudo mysqld --skip-grant-tables
 mysql -u root 
 mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
 mysql> FLUSH PRIVILEGES; 
 mysql> exit
 sudo mysqladmin shutdown -u root -p
 sudo /etc/init.d/mysql start
- Change mysql wikiuser password
 
 $ mysql -u root -p
 mysql> use mysql;
 mysql> update user set password=PASSWORD("NEWPASSWORD") where User='wikiuser';
 mysql> flush privileges;
 mysql> quit