<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Axino.net &#187; MySQL</title>
	<atom:link href="http://www.axino.net/category/programming/mysql-programming/feed" rel="self" type="application/rss+xml" />
	<link>http://www.axino.net</link>
	<description>The other side of atom.</description>
	<lastBuildDate>Thu, 15 Jul 2010 12:45:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to grant privilege to users on MySQL database</title>
		<link>http://www.axino.net/tutorial/2010/05/how-to-grant-privilege-to-users-on-mysql-database</link>
		<comments>http://www.axino.net/tutorial/2010/05/how-to-grant-privilege-to-users-on-mysql-database#comments</comments>
		<pubDate>Sun, 02 May 2010 21:09:02 +0000</pubDate>
		<dc:creator>Arxleol</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.axino.net/?p=818</guid>
		<description><![CDATA[If you need basics to start using your brand new mysql server without installing complex web interface. First of all we want to start up mysql: mysql -u root -p enter password Second thing is to create some database. create database dbname; Let&#8217;s create dbuser with name dbuser on localhost and password userpass. CREATE USER [...]]]></description>
			<content:encoded><![CDATA[<p>If you need basics to start using your brand new mysql server without installing complex web interface.</p>
<p><span id="more-818"></span></p>
<p>First of all we want to start up mysql:</p>
<pre>mysql -u root -p
enter password</pre>
<p>Second thing is to create some database.</p>
<pre>create database dbname;</pre>
<p>Let&#8217;s create dbuser with name dbuser on localhost and password userpass.</p>
<pre><code>CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'userpass';</code></pre>
<p>Following are two types of granting first one grants all permissions on database dbname to user dbuser accessing from localhost. Second version grants only select and insert permissions.</p>
<pre>GRANT ALL ON dbname.* TO 'dbuser'@'localhost';
GRANT SELECT, INSERT ON dbname.* TO 'dbuser'@'localhost';</pre>
<p>To see what permissions certain user has use following command. Notice that this will show you permissions of admin on localhost.</p>
<pre><code>SHOW GRANTS FOR 'admin'@'localhost';</code></pre>
<p>The following command is a bit more complex, if you have done something wrong this command will revoke all granted privileges. Afterwards select, insert, update and delete on every available database from any source address.</p>
<pre>REVOKE ALL PRIVILEGES ON *.* FROM 'dbuser'@'localhost'; REVOKE GRANT OPTION ON *.* FROM 'dbuser'@'localhost'; GRANT SELECT, INSERT, UPDATE, DELETE ON *.* TO 'dbuser'@'localhost'WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;</pre>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.axino.net/tutorial/2009/10/connect-to-mysql-database-in-java" rel="bookmark" title="Wednesday 21.10.2009">Connect to mysql database in java</a></li>
<li><a href="http://www.axino.net/tutorial/2009/05/local-domain-or-set-up-of-local-site" rel="bookmark" title="Monday 04.05.2009">Local domain || set up of local site</a></li>
<li><a href="http://www.axino.net/tutorial/2010/05/hackthissite-org-application-3-127-0-0-1" rel="bookmark" title="Thursday 27.05.2010">hackthissite.org Application 3 :: 127.0.0.1</a></li>
<li><a href="http://www.axino.net/tutorial/2009/11/basic-web-hacking-8-simple-sql" rel="bookmark" title="Monday 16.11.2009">Basic web hacking 8 :: simple SQL</a></li>
<li><a href="http://www.axino.net/tutorial/2010/05/mysql-server-and-ubuntu" rel="bookmark" title="Saturday 01.05.2010">mysql server and ubuntu</a></li>
</ul>
<p><!-- Similar Posts took 5.084 ms --></p>
 <img src="http://www.axino.net/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=818" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.axino.net/tutorial/2010/05/how-to-grant-privilege-to-users-on-mysql-database/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mysql server and ubuntu</title>
		<link>http://www.axino.net/tutorial/2010/05/mysql-server-and-ubuntu</link>
		<comments>http://www.axino.net/tutorial/2010/05/mysql-server-and-ubuntu#comments</comments>
		<pubDate>Sat, 01 May 2010 03:54:14 +0000</pubDate>
		<dc:creator>Arxleol</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[ubuntu]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.axino.net/?p=801</guid>
		<description><![CDATA[In previous tutorial I shortly explained how to install Java and Glassfish on Ubuntu based systems. If you have intentions to host some basic web site you probably intend to use some sort of database. For none-commercial projects I strongly suggest mysql since it is free for none commercial use. To install mysql server is [...]]]></description>
			<content:encoded><![CDATA[<p>In previous tutorial I shortly explained how to<a href="http://www.axino.net/programming/java-programming/2010/04/java-glassfish-and-ubuntu-server"> install Java and Glassfish</a> on Ubuntu based systems. If you have intentions to host some basic web site you probably intend to use some sort of database. For none-commercial projects I strongly suggest mysql since it is free for none commercial use.</p>
<p><span id="more-801"></span>To install mysql server is squite easy just enter following line in terminal:</p>
<pre>sudo apt-get install mysql-server</pre>
<pre></pre>
<p>When installed you can start or stop server by following lines, if it is installed to default location:</p>
<pre>sudo /etc/init.d/mysqld start</pre>
<pre>sudo /etc/init.d/mysqld stop</pre>
<p>Restarting server is similar:</p>
<p>sudo /etc/init.d/mysqld restart</pre>
<p><strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.axino.net/programming/java-programming/2010/04/java-glassfish-and-ubuntu-server" rel="bookmark" title="Friday 30.04.2010">java glassfish and ubuntu server</a></li>
<li><a href="http://www.axino.net/tutorial/2009/10/connect-to-mysql-database-in-java" rel="bookmark" title="Wednesday 21.10.2009">Connect to mysql database in java</a></li>
<li><a href="http://www.axino.net/tutorials" rel="bookmark" title="Wednesday 07.01.2009">Tutorials</a></li>
<li><a href="http://www.axino.net/tutorial/2010/05/how-to-grant-privilege-to-users-on-mysql-database" rel="bookmark" title="Sunday 02.05.2010">How to grant privilege to users on MySQL database</a></li>
<li><a href="http://www.axino.net/tutorial/2009/05/local-domain-or-set-up-of-local-site" rel="bookmark" title="Monday 04.05.2009">Local domain || set up of local site</a></li>
</ul>
<p><!-- Similar Posts took 4.922 ms --></p>
 <img src="http://www.axino.net/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=801" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.axino.net/tutorial/2010/05/mysql-server-and-ubuntu/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Connect to mysql database in java</title>
		<link>http://www.axino.net/tutorial/2009/10/connect-to-mysql-database-in-java</link>
		<comments>http://www.axino.net/tutorial/2009/10/connect-to-mysql-database-in-java#comments</comments>
		<pubDate>Wed, 21 Oct 2009 21:37:05 +0000</pubDate>
		<dc:creator>Arxleol</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[how to]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.axino.net/?p=497</guid>
		<description><![CDATA[Since this is not trivial as one might think. I will go slowly trough the process of creating connection and finally statement (reading data, writing or deleting ). First thing you need is access to the mysql server, I strongly suggest using WAMP or XAMPP for windows based users or LAMP or XAMPP for linux based users. After [...]]]></description>
			<content:encoded><![CDATA[<p>Since this is not trivial as one might think. I will go slowly trough the process of creating connection and finally statement (reading data, writing or deleting ).</p>
<p><span id="more-497"></span></p>
<p>First thing you need is access to the mysql server, I strongly suggest using <a href="http://www.wampserver.com/en/download.php" target="_blank">WAMP </a>or <a href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">XAMPP </a>for windows based users or <a href="http://www.sph.umich.edu/csg/abecasis/LAMP/download/" target="_blank">LAMP </a>or <a href="http://www.apachefriends.org/en/xampp-linux.html">XAMPP </a>for linux based users. After you install any of these packages you are required to start mysql database server (service). Of course if you want to create some sort of database you should either use command line interface for mysql or phpmyadmin which comes included in packages I suggested before. PhpMyAdmin is used for operating MySQL based database and great learning tool as it for any action you do trough interface you will be able to see SQL code.</p>
<p>Now let&#8217;s continue with Java.</p>
<p>To star connection you will require following code:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">Connection</span> conn <span style="color: #339933;">=</span> <span style="color: #003399;">DriverManager</span>.<span style="color: #006633;">getConnection</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jdbc:mysql://127.0.0.1:3306/somedb&quot;</span>, <span style="color: #0000ff;">&quot;root&quot;</span>, <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The following statement means that you are using <strong>java database connection</strong> using <strong>mysql protocol</strong> connecting to <strong>somedb </strong>meanwhile user with which you connect to database is <strong>root</strong> and this user is using <strong>empty password</strong> as it is default in the previously mentioned packages.</p>
<p>When you execute previous statement you are establishing connection to database. On the other hand very important thing is to close connection to database otherwise you will slow down your server and your application will work slowly.</p>
<p>To close connection to database you need to invoke method in Connection object:&#8221;</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">conn.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Now let&#8217;s say that we have table in the database <strong>somedb </strong>named <strong>students</strong>. Table students contains fields <strong>student_id</strong>, <strong>name</strong>, <strong>surname</strong>, <strong>citizenship</strong>.  To read data from this table we are going to use basic SQL statement.</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #66cc66;">*</span> <span style="color: #993333; font-weight: bold;">FROM</span> students</pre></div></div>

<p>Upper statement means that we select all fields that is all columns and rows from table students. Now let&#8217;s see how to execute this statement.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">PreparedStatement</span> studs <span style="color: #339933;">=</span> conn.<span style="color: #006633;">prepareStatement</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM students&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This means that we are preparing statement to be execute <em>trough</em> our established connection. Also if you have googled or binged then you might have noticed that some are using statement instead of preparedstatement. Difference is huge! Not in this particular example but as you get better it is always good to use proper programming from beginning then to start changing something later on when you figure that it is <strong>insecure</strong> or wrong. Yes the difference is in security just on short notice. In statement you can place trough SQL injection but if you use preparedstatement this will not pass checking or all special characters will be escaped.</p>
<p>Next step is to execute our query!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">ResultSet</span> rs <span style="color: #339933;">=</span> studs.<span style="color: #006633;">executeQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>This represents execution of preparedstatement studs. Returned object is ResultSet from which we are able to obtain data from database.</p>
<p>Now let&#8217;s say that you would like read data about student in the first row. You should use following code.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">rs.<span style="color: #006633;">getInt</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;student_id&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rs.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;name&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rs.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;surname&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
rs.<span style="color: #006633;">getString</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;citizenship&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Using that code you can obtain all data that can be stored in this table. To move on the next record you will use following method:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">rs.<span style="color: #006633;">next</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>And always remember to close the connection to the database!<strong>Similar Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.axino.net/tutorial/2010/05/how-to-grant-privilege-to-users-on-mysql-database" rel="bookmark" title="Sunday 02.05.2010">How to grant privilege to users on MySQL database</a></li>
<li><a href="http://www.axino.net/tutorial/2009/11/addind-content-in-jtable" rel="bookmark" title="Tuesday 03.11.2009">Addind content in JTable</a></li>
<li><a href="http://www.axino.net/tutorial/2010/05/mysql-server-and-ubuntu" rel="bookmark" title="Saturday 01.05.2010">mysql server and ubuntu</a></li>
<li><a href="http://www.axino.net/tutorial/2009/11/basic-web-hacking-8-simple-sql" rel="bookmark" title="Monday 16.11.2009">Basic web hacking 8 :: simple SQL</a></li>
<li><a href="http://www.axino.net/programming/java-programming/2010/04/java-glassfish-and-ubuntu-server" rel="bookmark" title="Friday 30.04.2010">java glassfish and ubuntu server</a></li>
</ul>
<p><!-- Similar Posts took 6.020 ms --></p>
 <img src="http://www.axino.net/wordpress/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=497" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.axino.net/tutorial/2009/10/connect-to-mysql-database-in-java/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
