Showing posts with label LINUX. Show all posts
Showing posts with label LINUX. Show all posts

Friday, 24 January 2014

MYSQL Database Create

|0 comments
Create a MySQL Database, Tables and Insert Data
Description: http://s0.cyberciti.org/images/category/old/mysqllogo.gif
How do I create a MySQL database, tables, and insert (store) data into newly created tables?

MySQL is a free and open source database management system. You need to use sql commands to create database. You also need to login as mysql root user account. To create a database and set up tables for the same use the following sql commands:
Tutorial details
Difficulty
Easy (rss)
Root privileges
No
Requirements
mysql
Estimated completion time
10m
1.  CREATE DATABASE - create the database. To use this statement, you need the CREATE privilege for the database.
2.  CREATE TABLE - create the table. You must have the CREATE privilege for the table.
3.  INSERT - To add/insert data to table i.e. inserts new rows into an existing table.
Procedure for creating a database and a sample table
Login as the mysql root user to create database:
$ mysql -u root -p
Sample outputs:
mysql>
Add a database called books, enter:
mysql> CREATE DATABASE books;
Now, database is created. Use a database with use command, type:
mysql> USE books;
Next, create a table called authors with name, email and id as fields:
mysql> CREATE TABLE authors (id INT, name VARCHAR(20), email VARCHAR(20));
To display your tables in books database, enter:
mysql> SHOW TABLES;
Sample outputs:
+-----------------+
| Tables_in_books |
+-----------------+
| authors         |
+-----------------+
1 row in set (0.00 sec)
Finally, add a data i.e. row to table books using INSERT statement, run:
mysql> INSERT INTO authors (id,name,email) VALUES(1,"Vivek","xuz@abc.com");
Sample outputs:
Query OK, 1 row affected (0.00 sec)
Try to add few more rows to your table:
mysql> INSERT INTO authors (id,name,email) VALUES(2,"Priya","p@gmail.com");
mysql> 
INSERT INTO authors (id,name,email) VALUES(3,"Tom","tom@yahoo.com");
To display all rows i.e. data stored in authors table, enter:
mysql> SELECT * FROM authors;
Sample outputs:
+------+-------+---------------+
| id   | name  | email         |
+------+-------+---------------+
|    1 | Vivek | xuz@abc.com   |
|    2 | Priya | p@gmail.com   |
|    3 | Tom   | tom@yahoo.com |
+------+-------+---------------+
3 rows in set (0.00 sec)


Share Folder Linux

|1 comments
How to install Samba server on CentOS 6

Part 1: Configuring anonymous share with samba server
To install the samba package,enter the following command:
sudo yum install samba samba-client samba-common
Description: http://rbgeek.files.wordpress.com/2012/05/426.jpg?w=630&h=63
Check the version of installed samba software by using this command:
smbd --version
Description: http://rbgeek.files.wordpress.com/2012/05/524.jpg?w=630&h=86
Configure the samba service, so that, it will start automatically at boot time:
sudo chkconfig smb on
sudo chkconfig nmb on
Description: http://rbgeek.files.wordpress.com/2012/05/on.jpg?w=630&h=100
Disable the SELinux:
sudo nano /etc/selinux/config
Description: http://rbgeek.files.wordpress.com/2012/05/157.jpg?w=630&h=73
Change SELinux from enforcing to disabled:
SELINUX=disabled
Description: http://rbgeek.files.wordpress.com/2012/05/230.jpg?w=630&h=230
Add these Iptables rules, so that samba will work perfectly:
sudo iptables -I INPUT 4 -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
sudo iptables -I INPUT 5 -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
sudo iptables -I INPUT 6 -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
sudo service iptables save
Description: http://rbgeek.files.wordpress.com/2012/05/325.jpg?w=630&h=194
Restart the Server!!!
Go to your Windows machine and use this command in order to check the WORKGROUP name:
net config workstation
Description: http://rbgeek.files.wordpress.com/2012/05/625.jpg?w=630&h=76
It will show the output, something like this:
Description: http://rbgeek.files.wordpress.com/2012/05/720.jpg?w=630&h=315
Backup the smb.conf file, then delete it and create the new one:
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo rm /etc/samba/smb.conf
sudo touch /etc/samba/smb.conf
sudo nano /etc/samba/smb.conf
Description: http://rbgeek.files.wordpress.com/2012/05/819.jpg?w=630&h=151
Add these lines, in your smb.conf file (or change it according to your requirement):
#======================= Global Settings =====================================
[global]
 workgroup = WORKGROUP
 security = share
 map to guest = bad user
#============================ Share Definitions ==============================
[MyShare]
 path = /samba/share
 browsable =yes
 writable = yes
 guest ok = yes
 read only = no
Description: http://rbgeek.files.wordpress.com/2012/05/919.jpg?w=630&h=396
Save the smb.conf file and restart the service:
sudo service smb restart
sudo service nmb restart
Description: http://rbgeek.files.wordpress.com/2012/05/1016.jpg?w=630&h=144
Access the samba share from windows (where centos is the name of my samba server):
Description: http://rbgeek.files.wordpress.com/2012/05/centos.jpg?w=630
wao, we are able to access the samba share successfully Description: :-)
Description: http://rbgeek.files.wordpress.com/2012/05/centos12.jpg?w=630
Let’s try to create something, inside the share folder:
Description: http://rbgeek.files.wordpress.com/2012/05/1119.jpg?w=630&h=454
Error, we cannot create anything inside the share folder Description: :-(
Description: http://rbgeek.files.wordpress.com/2012/05/1213.jpg?w=630&h=350
Check the current permission on the samba share:
cd /samba/
ls -l
Description: http://rbgeek.files.wordpress.com/2012/05/1312.jpg?w=630&h=131
Change it, in such a way that everyone can read and write it(Check it, that it is allowed in your environment or not):
sudo chmod -R 0777 share
ls -l
Description: http://rbgeek.files.wordpress.com/2012/05/1412.jpg?w=630&h=129
Try to create something again, inside the share folder:
Description: http://rbgeek.files.wordpress.com/2012/05/158.jpg?w=630
Verify the newly created file on samba server:
cd share/
ls -l
Description: http://rbgeek.files.wordpress.com/2012/05/163.jpg?w=630&h=133
Part 2: Add and manage users and groups
Add a group in your CentOS server (in my case smbgrp):
sudo groupadd smbgrp
Description: http://rbgeek.files.wordpress.com/2012/05/174.jpg?w=630&h=82
Create a new share, set the permission on the share:
cd /samba/
sudo mkdir secure
sudo chown -R arbab:smbgrp secure/ 
ls -l 
sudo chmod -R 0770 secure/
ls -l
Description: http://rbgeek.files.wordpress.com/2012/05/181.jpg?w=630&h=296
Add the user to the samba group and create samba password:
sudo usermod -a -G smbgrp arbab
sudo smbpasswd -a arbab
Description: http://rbgeek.files.wordpress.com/2012/05/191.jpg?w=630&h=142
Edit the smb.conf file:
sudo nano /etc/samba/smb.conf
Description: http://rbgeek.files.wordpress.com/2012/05/201.jpg?w=630&h=76
Add the newly created samba share in smb.conf file:
[Secure]
path = /samba/secure
 valid users = @smbgrp
 guest ok = no
 writable = yes
 browsable = yes
Description: http://rbgeek.files.wordpress.com/2012/05/2110.jpg?w=630&h=395
Restart the samba service:
sudo service smb restart
sudo service nmb restart
Description: http://rbgeek.files.wordpress.com/2012/05/2210.jpg?w=630&h=133
Check the syntax error with testparm:
sudo testparm
Description: http://rbgeek.files.wordpress.com/2012/05/232.jpg?w=630&h=393
Testing from Windows Machine:
Description: http://rbgeek.files.wordpress.com/2012/05/241.jpg?w=630&h=492
Description: http://rbgeek.files.wordpress.com/2012/05/251.jpg?w=630&h=493
Verification from CentOS server:
cd /samba/secure/
ls -l 
Description: http://rbgeek.files.wordpress.com/2012/05/261.jpg?w=630&h=129