{"id":2281,"date":"2013-07-12T15:31:47","date_gmt":"2013-07-12T07:31:47","guid":{"rendered":"http:\/\/rmohan.com\/?p=2281"},"modified":"2013-07-12T16:25:27","modified_gmt":"2013-07-12T08:25:27","slug":"mysql-database-in-linux","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=2281","title":{"rendered":"Mysql DataBase in linux"},"content":{"rendered":"<div>We\u00a0 can check how to install mysql db in a linux machine<\/div>\n<div>All files of mysql including DB are stored in\u00a0\/var\/lib\/mysql\/<\/div>\n<p>&nbsp;<\/p>\n<div>All configuration files are in\u00a0\/etc\/my.cnf<\/div>\n<p>&nbsp;<\/p>\n<div>Install the package using yum<\/div>\n<div># yum install mysql mysql-server<\/div>\n<p>&nbsp;<\/p>\n<div>And then start the mysql server<\/div>\n<div># service mysqld start<\/div>\n<p>&nbsp;<\/p>\n<div>Here no root password set for the DB so any one can access the DB command<\/div>\n<div># mysql<\/div>\n<p>&nbsp;<\/p>\n<div>For securing it set a root password for mysql<\/div>\n<div># mysqladmin -u root password &#8216;password&#8217;<\/div>\n<p>&nbsp;<\/p>\n<div>this will set a root password for mysql. If you want to update the mysql root password the do the following<\/div>\n<div># mysqladmin -u root -p&#8217;oldpassword&#8217; password &#8216;newpassword&#8217;<\/div>\n<p>&nbsp;<\/p>\n<div>Then to enter into mysql database run<\/div>\n<div># mysql -u root -p<\/div>\n<div>enter password:<\/div>\n<div><\/div>\n<div>or we can specify password after -p option but it will be visible to all<\/div>\n<div><\/div>\n<div>Now your\u00a0 mysql data base is ready for operation with a default port of\u00a03306.<\/div>\n<p>&nbsp;<\/p>\n<div>Some basic mysql queries are<\/div>\n<div>To list all databases on the mysql sql server<\/div>\n<div>mysql&gt; show databases;<\/div>\n<p>&nbsp;<\/p>\n<div>Create a database on the sql server<\/div>\n<div>mysql&gt; create database [databasename];<\/div>\n<p>&nbsp;<\/p>\n<div>To use a database<\/div>\n<div>mysql&gt; use dbname;<\/div>\n<p>&nbsp;<\/p>\n<div>To create a table in the database<\/div>\n<div>mysql&gt; create table tablename(name varchar(20),dob int(20));<\/div>\n<p>&nbsp;<\/p>\n<div>To see all the tables in the db<\/div>\n<div>mysql&gt; show tables;<\/div>\n<p>&nbsp;<\/p>\n<div>To drop a particular table<\/div>\n<div>mysql&gt; drop table tablename;<\/div>\n<p>&nbsp;<\/p>\n<div>To see the structure of a particular table<\/div>\n<div>mysql&gt; describe employee;<\/div>\n<div>mysql&gt; show columns from table-name;<\/div>\n<p>&nbsp;<\/p>\n<div>Show all data in a table<\/div>\n<div>mysql&gt; SELECT * FROM [table name];<\/div>\n<p>Granting\u00a0 Database permission to a user, * will give all default permissions<b><br \/>\n<\/b><\/p>\n<div>mysql&gt; grant usage on *.* to &#8216;ctechz&#8217;@&#8217;localhost&#8217; identified by &#8216;ctechz123&#8217;;<\/div>\n<p>&nbsp;<\/p>\n<div>Granting\u00a0 particular permission to users,<\/div>\n<div>mysql&gt; grant select,insert,update,delete,create,drop on TestDb.* to &#8216;ctechz&#8217;@&#8217;localhost&#8217; identified by\u00a0 &#8216;ctechz123&#8217;;<\/div>\n<p>&nbsp;<\/p>\n<div>Creating a user to access db<\/div>\n<div>mysql&gt; create user ctechz identified by &#8216;ctechz123&#8217;;<\/div>\n<p>&nbsp;<\/p>\n<div>To change the password for a user<\/div>\n<div>mysql&gt; set password for &#8216;ctechz&#8217;@&#8217;localhost&#8217;=password(&#8216;ctechz123&#8217;);<\/div>\n<div>\u00a0mysql&gt; flush privileges;<\/div>\n<p>&nbsp;<\/p>\n<div>Granting permission from any host<\/div>\n<div>mysql&gt; GRANT ALL PRIVILEGES ON *.* TO &#8216;monty&#8217;@&#8217;%&#8217; WITH GRANT OPTION;<\/div>\n<p>% means for all host<\/p>\n<div>We can get the mysql history file from<\/div>\n<div>\u00a0\u00a0# vim .mysql_history<\/div>\n<div>from the above file we can get the commands that we run the mysql bd.<\/p>\n<div>If you want to connect to a remote mysql server from your machine<\/div>\n<p>#\u00a0 mysql -uroot -p -h 192.168.1.245<\/p>\n<div>Granting permission to access the database from a particular Ip<\/div>\n<p># grant all privileges on *.* to &#8216;root&#8217;@&#8217;192.168.1.67&#8217; identified by &#8216;mysql1&#8217;;<\/p>\n<div># flush privileges;<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>We can check how to install mysql db in a linux machine All files of mysql including DB are stored in \/var\/lib\/mysql\/ <\/p>\n<p>&nbsp;<\/p>\n<p> All configuration files are in \/etc\/my.cnf <\/p>\n<p>&nbsp;<\/p>\n<p> Install the package using yum # yum install mysql mysql-server <\/p>\n<p>&nbsp;<\/p>\n<p> And then start the mysql server # service mysqld start <\/p>\n<p>&nbsp;<\/p>\n<p> Here no root [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2281"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2281"}],"version-history":[{"count":8,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2281\/revisions"}],"predecessor-version":[{"id":2289,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/2281\/revisions\/2289"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2281"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2281"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2281"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}