Skip to main content

DB's and Users

Create a DB
 
 
 
 
 
1
CREATE DATABASE new_database;
 
 
Drop a DB
 
 
 
 
 
1
DROP DATABASE new_database;
 
 
Create a new user with all prems
 
 
 
 
 
1
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
 
 

GRANT [type of permission] ON [database name].[table name] TO ‘[username]’@'localhost’;

REVOKE [type of permission] ON [database name].[table name] FROM ‘[username]’@‘localhost’;

 
 
 
 
 
1
GRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';
 
 
 
 
 
 
 
1
FLUSH PRIVILEGES;
 
 
Add user to 1 DB
 
 
 
 
 
1
GRANT ALL PRIVILEGES ON new_database . * TO 'newuser'@'localhost';
 
 
To drop a user:
 
 
 
 
 
1
DROP USER ‘newuser’@‘localhost’;
 
 

Innodb recovery

What we will need to do for the recovery is to stop mysql and put it in innodb_force_recovery to attempt to backup all databases.

 
 
 
 
 
1
service mysqld stop
2
mkdir /root/mysqlbak
3
cp -rp /var/lib/mysql/ib* /root/mysqlbak
4
vim /etc/my.cnf
 
 

You can start from 1 to 4, go up if it does not start and check mysql logs if it keeps crashing.

innodb_force_recovery = 1

 
 
 
 
 
1
service mysqld start
2
mysqldump -A > dump.sql
 
 

Drop all databases that needs recovery.

 
 
 
 
 
1
service mysqld stop
2
rm /var/lib/mysql/ib*
 
 

Comment out innodb_force_recovery in /etc/my.cnf

 
 
 
 
 
1
service mysqld start
 
 
  

Then check /var/lib/mysql/server/hostname.com.err to see if it creates new ib's.
Then you can restore databases from the dump:mysql < dump.sql