Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Feb 25, 2014

If you want reset your MySQL root password follow the below simple steps.

Stop MySQL server
# service mysql stop
Restart MySQL with option --skip-grant-tables, i.e permissions are not loaded and so disable networking
# /usr/sbin/mysql --skip-grant-tables --skip-networking
Now login to the mysql shell as root user, and no password
# mysql -u root
The user passwords are in the table mysql.user in password column update them
mysql>use mysql;
mysql>update user set password=password('inctfmysql') where user='root';
Now give the below command to commit the changes
mysql>flush privileges;
Restart the MySQL server
# service mysql restart

Feb 6, 2014

Backup and Restore operation in MySQL Server.

Some handy MySQL tips before we move on:

How to log into mysql shell ?
Type the below command in the terminal
mysql --user=username --password=password

Know the version of my MySQL server ?
After you log in to mysql shell check out the first few lines, it will have the server version.

See all databases in mysql ?
From mysql shell, type the command 'show databases'.
mysql show databases

Set a database as working or current database ?
From mysql shell, type the command use database_name
mysql --user=username --password=password

See all the tables in my current selected database ?
From mysql shell, type the command 'show tables'
mysql show tables

How to take BackUp

To take back up of all databases
Type the the below in your terminal 
mysqldump --user=username --password=password --all-databases > alldbbck.sql

To take back up of a single database
Give the below command from your terminal
mysqldump --databases db1 > dump.sql
mysqldump  db1 > dump.sql

If we use '--databases' then the dump.sql will have 'CREATE DATABASE db1' and 'USE db1' statements, so while restoring this script you need not specify the target database name for recreation of tables, MySQL will create the database for you.

To take back up of a multiple database
Use the below command
mysqldump --databases db1 db2 db3 > dump.sql

How to Restore

If the dump script have create database and use statements (i.e created using --all-databases                  or --databases option) then it's not necessary to specify a database in which the backup is to be restored.
Fire the below command from your terminal:
mysql --user=username --password=password < dump.sql

MySQL will create the database for you as your script already have the 'CREATE DATABASE' statement.

Otherwise specify an existing database as destination database
mysql --user=username --password=password dump < dump.sql

This post covered the most basic and steps for backup and restore, a shot for the jump in guys..
Happy Hacking !!
Harden MySQL installation was a task in InCTF 2014 learning round. Below are the steps I used to harden MySQL installation on my Ubuntu 13.04 box.

Basic MySQL installation
sudo apt-get install mysql-server

Securing MySQL
Type the below command to start the secure setup script
sudo /usr/bin/mysql_secure_installation

This will launch the secure installation script

Setting root password:
If you had not set the root password at the time of installation systems asks you to set it now. I had already set the root password, so I'm skipping.

Remove anonymous users:
By default MySQL have anonymous login with no passwords, so remove it.

Disallow remote root login:
To make sure some one brute force or guess your root user password and attempt to remotely login into your database server.

Remove default 'test' database:
MySQL is shipped with a default 'test' database that anyone can access, it's purely only for testing and should be removed.

Reload the privileges table:
To make all the changes reflect reload the privileges table.