I apologise for delay in my posting. Now I understood “without planning” nothing will work out. Ok Cool
Lets come to the topic.
I have been working in MySQL in my college days about a year ago. But yesterday when I thought of configuring and starting again, Just a . So I prepared a kutti guide. Thats for you.
***** Installing MySQL on Linux *****
1. (i) Install MySQL Server (55MB)
(ii) PHPMyadmin (70MB) – For GUI Mode of Creating,manipulating and syndicating the database (Optional but powerful)
If you have internet connection, then for Fedora users
*** RPM Package Distro’s ***
# yum-install mysql-server
*** DEB Package Distro’s ***
# apt-get install mysql-server
Note : If you dont have the internet connection, then just download the packages with dependencies and install from your local filesystem
***** Start/Stop the database *****
2. Check for the successful installation of MySQL database and check for the status. whether it is up and running/stopped,etc..
********* RPM Distro’s *********
# /etc/rc.d/init.d/mysqld start/stop/status/restart [or]
# service [damon] start/stop/status/restart [or] /* Damon name of mysql is mysqld */
Esp. for stopping mysql shutdown option is preferred than stop
# mysqladmin -h [host] -u [user] -p[password] shutdown
Turn on mysqld when system boots
# chkconfig mysqld on
*** DEB Distro’s ***
# /etc/init.d/mysqld start/stop/status/restart [or]
# service mysql start/stop/status/restart [or]
Turn on mysqld when system boots
# sysv-rc-conf mysql on
***** Creating user for the database *****
3. Creating mysql users and setting the password and updating them.
# mysqladmin -u root -p password [new-password] [or]
For Update : Goto MySQL Prompt by
# mysql -u localhost -u [user] -p [mysql_user_password]
mysql> SET PASSWORD FOR root@’localhost’ = PASSWORD(‘[new_password]‘); [or]
mysql> UPDATE user SET Password=PASSWORD(‘new-password’) WHERE user=’root’;
To make that changes to be reflected on the DB
mysql> FLUSH PRIVILEGES; [or]
# mysqladmin reload
Note : # – denotes root shell (The teminal which is initialised with root user)
mysql> – denotes the mysql prompt for creating and manipulating the DB
; – denotes the end the statements/queries in the MySQL Prompt .
***** Changing the configuration of the database *****
4. Locate the MySQL database and configuration files on the filesystem
Configuration file : /etc/mysql/my.cnf
Location : /var/lib/mysql (Under this directory, you can see you list of databases created on the MySQL)
***** Setting permission for the database and tables *****
mysql> grant all privileges on [database].* to [user]@”localhost” identified by ‘[password]‘;
***** Creating tables in the MySQL DB *****
[Use as usual SQL (Structured Query Language) to interact with the Database]
5. Creating the DB and Tables and executing the SQL Queries.
Before proceeding with the DDl and DML’s you should connect with the Database :
mysql> use [db_name];
then…
You can excecute the SQL’s in two ways.
1) Directly using them as commands:
mysql> CREATE TABLE …. [DDL]
2) Load all the SQL into the file and give the file as the input to the mysql Engine.
# mysql -u root -p [DB] < [SQL_file]
***** MySQL BackUp and Restoration *****
6. Essential part of development is nothing but backup and restoration because you can stuck at any point of time. So you should always have a checkpoint to proceed with.
[DB_BACKUP]
# mysqldump –add-drop-table -u [mysqluser] -p[password] [DB] > [filepath]
-a /* for backuping all the database */
[DB_RESTORE]
# mysql –add-drop-table -u [mysqluser] -p[password] [DB] < [backup_file]
[TABLE_BACKUP]
mysql> SELECT * INTO OUTFILE ‘[filepath]‘ FROM [tablename];
[TABLE_RESTORE]
mysql> LOAD DATA INFILE ‘[filepath]‘ REPLACE/IGNORE INTO TABLE [tablename];
REPLACE – Existing key values and data will be overridden
IGNORE – Only new records will be inserted
Enjoy digging the DB.
Keep Rocking.