Thursday 18 April 2013

Install Configure MySQL Server in Ubuntu

Install MySQL 
                                    

Type the following command to install MySQL server and client
sudo apt-get install mysql-server mysql-common mysql-client

to check the service
sudo netstat -tap | grep mysql
Edit /etc/mysql/my.cnf, enter:
sudo vi /etc/mysql/my.cnf

bind-address = 192.168.0.5
Review MySQL settings (the defaults are fine for small usage). To start / stop / restart mysql use the following commands:
sudo /etc/init.d/mysql start
sudo /etc/init.d/mysql stop 
sudo /etc/init.d/mysql restart

Set MySQL root User Password
By default there is no root password for MySQL. Type the Following command to set password:
mysqladmin -u root password 'My-Secret-Password'

Create a Sample Database and User For Testing Purpose
First connect to server, enter:
mysql -u root -p
 Enter password: 
Sample Outputs:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 37
Server version: 5.5.34-0ubuntu0.12.04.1 (Ubuntu
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.lear the buffer. mysql> 
 
Create a database called testdb, type the following at 
mysql> prompt:

mysql> CREATE DATABASE testdb;
Create a user called rahul with password redhat@123, enter:
 
mysql> GRANT ALL ON testdb.* TO rahul@localhost IDENTIFIED BY 'redhat@123';
mysql>FLUSH PRIVILEGES;

To show the database type the command:
mysql>show databases;
To quit just type \q and hit [Enter] key.

No comments:

Post a Comment