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

Tuesday, February 3, 2015

Query to find size of MySQL DB

When we are using shared hosting server with Windows or Linux, without any control panel software, It's little bit hard to find user's disk usage on mysql.

In this case we can use  following command on mysql to get size of database.

SELECT table_schema "DB Name", Round(Sum(data_length + index_length) / 1024 / 1024, 1) "DB Size in MB" FROM information_schema.tables GROUP  BY table_schema;

Friday, October 24, 2014

Copy mysql database table by query / command line

We can find lot of solutions to make copy of table.
Here is one of the simple solution which I got while google.

Copy table with in a Database

use databasename;

CREATE TABLE exampletable_copy LIKE exampletable;
INSERT exampletable_copy SELECT * FROM exampletable; 


Copy table from Database-1 to Database-2

use databasename2;

CREATE TABLE exampletable_copy LIKE exampletable.databasename1;
INSERT exampletable_copy SELECT * FROM exampletable.databasename1; 


Hint:
First query used to create table with structure of original table.
Second query used to copy data from table to table-copy.

Tuesday, January 18, 2011

Learning MySQL on linux - Installation

MySQL on Linux

MySQL - Installation 

Installing mysql on Redhat is very simple wia repostory also packages are avaliable in redhat dvd itself. For more information click, dvd repository and rpm forge. For detailed installation about MySQL with all systems check this page.

Normaly MySQL having 2 parts,
  • MySQL Server
  • MySQL Client
MySQL server -  It's program to managing storage of data

MySQL Client - It's a program for user intraction and we can get stored data by queries. 

Installing MySQL with repository

Open terminal window and in root account, run following comment

#yum install mysql*


type y and hit enter, this will install MySQL on your redhat system.

For start MySQL,

in terminal type " service mysqld start " without cotes.



For check status of MySQL running on your linux box, in terminal type "service mysqld status " without cotes.


Login in to MySQL on linux box,

In terminal window, type

#mysql -u root mysql

and hit enter, you get a mysql prompt as follow,



In mysql -u root mysql,

mysql :
mysql -u root mysql

highlighted 'mysql' will start mysql client for user intraction.

-u :
mysql -u root mysql

highlighted '-u' says to MySQL chient which user want to login into MySQL server.

root :
mysql -u root mysql

highlighted 'root' mentioning mysql should login as root user. (It's not linux root user, It's root user of MySQL server). It gives full control of MySQL server.

mysql:
mysql -u root mysql
highlighted 'mysql' is a database, this database in by default in MySQL server. It have several table.

Set password for MySQL user:

type following command after login in to mysql server,

mysql>SET PASSWORD FOR root@localhost=PASSWORD('rootpass');

here,

SET PASSWORD FOR root@localhost=PASSWORD('rootpass');

highlighted things are queries,

root@localhost, is user name with host address ,

rootpass is password for root login.

Learning MySQL on linux - Introduction

MySQL on Linux

MySQL - Introduction

MySQL is a relational database management system (RDBMS).

The Database is a system for store, organize and retrieve large amount of data fast and easily. It have a collection of data for multiple uses in digital form.

A Database Management System (DBMS) is a set of computer programs that controls the creation, maintenance, and the use of a database. A DBMS is a system software package that helps the use of integrated collection of data records and files known as databases. It allows different user application programs to easily access the same database. In large systems, a DBMS allows users and other software to store and retrieve data in a structured way. Instead of having to write computer programs to extract information, user can ask simple questions in a query language. DBMSs may use any of a variety of database models, such as the network model or relational model.

A Database model is the theoretical foundation of a database and fundamentally determines in which manner data can be stored, organized and manipulated in a database system. It thereby defines the infrastructure offered by a particular database system. The most popular example of a database model is the relational model.

Models:
  • Hierarchical model
  • Network model
  • Relational model
  • Entity-relationship
  • Object-relational model
  • Object model

The relational model for database management is a database model based on first-order predicate logic, first formulated and proposed in 1969 by E.F. Codd.

A relational database management system (RDBMS) is a database management system (DBMS) that is based on the relational model as introduced by E. F. Codd. Most popular commercial and open source databases currently in use are based on the relational database model.
A short definition of an RDBMS may be a DBMS in which data is stored in the form of tables and the relationship among the data is also stored in the form of tables.
SQL - Structured Query Language is database computer language designed for managing data in Relational database management system. ( Developed by IDM )

MySQL - is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases. The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish company MySQL AB, now owned by Oracle Corporation.

Difference between SQL & MySQL

SQL (Structured Query Language) is computer language that can be used to access data stored in relational databases.  SQL is not itself a standalone computer application, but is part of many relational Database programs like MySQL, Oracle, Sybase, Microsoft SQL Server, etc.

MySQL is open source database management system. It's an application. It've SQL interpreter, a database manager component, GUI database viewers, and session monitoring tools, etc. MySQL is a multithreaded, multi-user SQL database management system (DBMS) providing multi-user access to a number of databases. 

The difference between SQL and MySQL are like, difference between HTML and Dreamweaver. HTML is webpages standard, dreamweaver is computer application that can be used to create, edit webpages.


Reference : Wikipedia and some websites on Internet.