Questions about this topic? Sign up to ask in the talk tab.

Difference between revisions of "MySQL"

From NetSec
Jump to: navigation, search
(Setup on a personal computer)
Line 23: Line 23:
 
<syntaxhighlight lang="SQL">
 
<syntaxhighlight lang="SQL">
 
CREATE USER K_Mitnick;
 
CREATE USER K_Mitnick;
 +
</syntaxhighlight>
 
|}
 
|}
  
Line 30: Line 31:
  
 
=== Setting Permissions ===
 
=== Setting Permissions ===
 +
 +
In order to allow your users to execute queries and interact with your databases, you must indicate to the server just what they are allowed to do. The most simple form of this is
 +
 +
{| class="wikitable"
 +
|
 +
<syntaxhighlight lang="SQL">
 +
GRANT ALL ON <database name> TO <username> IDENTIFIED BY '<password>';
 +
</syntaxhighlight>
 +
|}

Revision as of 00:45, 20 October 2011

MySQL Setup

In order to run MySQL you will need a MySQL server to work with - you can establish a server on one of your own computers, or use a webserver with MySQL installed.

Setup on a personal computer

Once MySQL is installed on your computer and the MySQL daemon is running (in Arch, /etc/rc.d/mysqld start), the next step is to establish users. If you defined a root MySQL password on setup, you can use this to establish a new user; otherwise, just hit enter at any password prompts you encounter.

In order to set up your MySQL databases, you'll first need to log into MySQL - at this point the only MySQl user will be your root user, so log in with:

<syntaxhighlight lang="bash"> mysql -u root -p <root password> </syntaxhighlight>

This will log you int MySQl as root. At this point, you can establish your other users with the SQL CREATE USER query. For example, if you wanted to create a user, "K_Mitnick":

<syntaxhighlight lang="SQL"> CREATE USER K_Mitnick; </syntaxhighlight>

Note the terminating semicolon - this indicates to MySQl that you wish to send your input as a query. Another method of doing this is by terminating your queries with '\g' - there is no difference between the two, it is simply a matter of personal preference.

This user will be created with absolutely no privileges: they can log into your server but do little else.

Setting Permissions

In order to allow your users to execute queries and interact with your databases, you must indicate to the server just what they are allowed to do. The most simple form of this is

<syntaxhighlight lang="SQL"> GRANT ALL ON <database name> TO <username> IDENTIFIED BY '<password>'; </syntaxhighlight>