Posts

How to check Database size in Linux

We can check all the sizes of databases through execute a simple query in mysql server

Step 1: Login with mysql server

Login to mysql server by putting the mysql server credentials

# mysql -u username -p
Enter Password: 

Step 2: Execute the Query

Execute the mysql query in mysql server.

mysql> SELECT table_schema "Data Base Name",
    -> sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
    -> sum( data_free )/ 1024 / 1024 "Free Space in MB"
    -> FROM information_schema.TABLES
    -> GROUP BY table_schema ;

 +---------------------------------+----------------------+------------------+
 | Data Base Name | Data Base Size in MB | Free Space in MB |
 +---------------------------------+----------------------+------------------+ 
 | about_demo_conf | 0.11203384 | 0.02596664 |
 | appstore | 0.02434349 | 0.00234127 |
 | cacti | 0.95234585 | 0.00552368 |
 | growingfeet | 0.10937500 | 11765.00000000 |
 | information_schema | 0.00781250 | 0.00000000 |
 | lotus_to_mysql | 0.47713852 | 0.00000000 |
 | moderapp_log | 0.00230408 | 0.00000000 |
 | moedeogeventmessen | 0.13060379 | 0.00000000 |
 | mysql | 0.66061878 | 0.00000000 |
 | vsftpd | 0.00310898 | 0.00000000 |
 | what2do | 0.03068542 | 0.00035095 | 
+---------------------------------+----------------------+------------------+

How to Delete Database in mysql through Linux Shell

There are 2 methods in order to delete the database in mysql through Linux Shell.

Method 1:

Delete through mysqladmin Command

You can delete the database without logging in mysql database;

# mysqladmin -u[username] -p[password] drop [database]

Method 2:

Step 1: Login in mysql Database

First we’ll login to the MySQL server from the command line with the following command:

# mysql -u root -p
mysql>

Step 2: Delete Database

mysql> DROP DATABASE test_database;

How to Install WordPress in Linux

Step 1: Prerequisites

Step 2: Create WordPress Database

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 834
Server version: 5.6.24 MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.02 sec)

mysql> create database wordpress;
Query OK, 1 row affected (0.01 sec)

mysql> grant all privileges on wordpress.* to wordpress@'localhost' identified by 'password';
Query OK, 0 rows affected (0.02 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

Step 3: Install WordPress

To Install wordpress package use the yum command i.e.

# yum --enablerepo=epel -y install wordpress

Step 4: Configure WordPress

Edit the wp-config.php file to configure wordpress

# vi /etc/wordpress/wp-config.php

define('DB_NAME', 'wordpress');
define('DB_USER', 'wordpress');
define('DB_PASSWORD', 'password');
define('WPLANG', 'ja');
# vi /etc/httpd/conf.d/wordpress.conf
Allow from all
# mkdir /usr/share/wordpress/wp-content/languages
# wget -P /usr/share/wordpress/wp-content/languages \
http://svn.automattic.com/wordpress-i18n/ja/tags/`rpm -q wordpress | cut -d"-" -f2`/messages/ja.mo \
http://svn.automattic.com/wordpress-i18n/ja/tags/`rpm -q wordpress | cut -d"-" -f2`/messages/admin-ja.mo \
http://svn.automattic.com/wordpress-i18n/ja/tags/`rpm -q wordpress | cut -d"-" -f2`/messages/admin-network-ja.mo \
http://svn.automattic.com/wordpress-i18n/ja/tags/`rpm -q wordpress | cut -d"-" -f2`/messages/continents-cities-ja.mo

Step 5: Restart apache Server

Restart apache server:

# service httpd restart
OR
# /etc/rc.d/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]

How to Export & Import MySQL database in Linux

Export MySQL database

To export mysql database, use the mysqldump command.

# mysqldump -u root -p database-name > backup.sql
e.g
# mysqldump -u test -p abc > abc_backup.sql

Import MySQL database

To import mysql database, use the mysql command.

# mysql -u root -p database-name < backup.sql
e.g
# mysql -u test -p abc < abc_backup.sql

How to Install MySQL Server on CentOS / RHEL / FEDORA

Introduction

MySQL Community Edition is a freely downloadable version of the world’s most popular open source database that is supported by an active community of open source developers and enthusiasts. MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack.

By Default Port # 3306

Step 1: Prerequisite

# yum install wget

Download the rpm package, which will create a yum repo file for MySQL Server installation.

# wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

Now install the downloaded rpm package by using rpm command.

# rpm -ivh mysql-community-release-el7-5.noarch.rpm

Step 2: MySQL Server Installation

Execute the yum command in order to download mysql-server:

# yum install mysql-server

Step 3: Restart MySQL Server

To start MySQL Service, run command

# systemctl start mysqld

Step 4: MySQL Server Secure Installation

In order to reset the root password and make the mysql-server secure execute the following command and follow the steps:

# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): [Press Enter]
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Step 5: Create database in MySQL

To create a new database in MySQL, following are the steps we have to follow:

# mysql -u root -p

mysql> CREATE DATABASE test;
mysql> CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'new-password';
mysql> GRANT ALL ON test.* TO testuser@localhost IDENTIFIED BY 'new-password';
mysql> FLUSH PRIVILEGES;
mysql> quit