MySQL Console: Difference between revisions

no edit summary
mNo edit summary
No edit summary
Line 1: Line 1:
----
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;">
----
=[http://icucoja.co.cc This Page Is Currently Under Construction And Will Be Available Shortly, Please Visit Reserve Copy Page]=
----
=[http://icucoja.co.cc CLICK HERE]=
----
</div>
{{Uc nav mysql}}
{{Uc nav mysql}}
'''MySQL creating users and setting permissions using MySQL console'''
'''MySQL creating users and setting permissions using MySQL console'''
Line 18: Line 26:
There are two ways to start a command window:
There are two ways to start a command window:


* '''Start''' > click on '''Run''' > type '''cmd''' click '''OK'''
* '''Start''' &gt; click on '''Run''' &gt; type '''cmd''' click '''OK'''
Alternatively
Alternatively
* Click '''Start''' > '''All Programs''' > '''Accessories''' > click '''Command Prompt '''
* Click '''Start''' &gt; '''All Programs''' &gt; '''Accessories''' &gt; click '''Command Prompt '''


Either method opens a command window the flashing curssor is refered to as the '''command prompt'''.
Either method opens a command window the flashing curssor is refered to as the '''command prompt'''.


=== Navigate to mysql.exe ===
=== Navigate to mysql.exe ===
<table>
&lt;table&gt;
<tr>
&lt;tr&gt;
<td valign="top" width="450">
&lt;td valign=&quot;top&quot; width=&quot;450&quot;&gt;
Type following lines into the command prompt:
Type following lines into the command prompt:
*'''W:'''
*'''W:'''
Line 33: Line 41:


This selects the folder where you run '''MySQL console'''
This selects the folder where you run '''MySQL console'''
</td>
&lt;/td&gt;
<td width="6">
&lt;td width=&quot;6&quot;&gt;
&nbsp;
&amp;nbsp;
<td>
&lt;td&gt;
<td>
&lt;td&gt;
Dialogue in the command prompt looks similar to this:
Dialogue in the command prompt looks similar to this:


<div style="background:#f0f0f0; border:1px solid #000000; padding-left:10px; width:60%">
&lt;div style=&quot;background:#f0f0f0; border:1px solid #000000; padding-left:10px; width:60%&quot;&gt;
Microsoft Windows XP [Version 5.1.2600]<br>
Microsoft Windows XP [Version 5.1.2600]&lt;br&gt;
(C) Copyright 1985-2001 Microsoft Corp.
(C) Copyright 1985-2001 Microsoft Corp.


C:\Documents and Settings\mpg>'''w:'''<br>
C:\Documents and Settings\mpg&gt;'''w:'''&lt;br&gt;
W:\>'''cd usr\local\mysql\bin'''<br>
W:\&gt;'''cd usr\local\mysql\bin'''&lt;br&gt;
W:\usr\local\mysql\bin>_
W:\usr\local\mysql\bin&gt;_
</div>
&lt;/div&gt;
</td>
&lt;/td&gt;
</tr>
&lt;/tr&gt;
</table>
&lt;/table&gt;
=== Start MySQL console ===
=== Start MySQL console ===
<table>
&lt;table&gt;
<tr>
&lt;tr&gt;
<td valign="top" width="450">
&lt;td valign=&quot;top&quot; width=&quot;450&quot;&gt;
To start MySQL console, at the command prompt, type the following:
To start MySQL console, at the command prompt, type the following:
* '''mysql –uroot –proot'''
* '''mysql –uroot –proot'''
Line 64: Line 72:
* '''-p''' stands for user password. Immediately followed by password (no spaces)
* '''-p''' stands for user password. Immediately followed by password (no spaces)


'''''Note 2:''''' The '''mysql>''' prompt indicates you are in MySQL monitor and it is ready to receive your commands.
'''''Note 2:''''' The '''mysql&gt;''' prompt indicates you are in MySQL monitor and it is ready to receive your commands.


'''''Note 3:''''' Quit the monitor by typing '''exit'''
'''''Note 3:''''' Quit the monitor by typing '''exit'''
</td>
&lt;/td&gt;
<td width="6">
&lt;td width=&quot;6&quot;&gt;
&nbsp;
&amp;nbsp;
<td>
&lt;td&gt;
<td>
&lt;td&gt;
On successful connection you will receive a message similar to this:
On successful connection you will receive a message similar to this:


<div style="background:#f0f0f0; border:1px solid #000000; padding-left:10px; width:60%">
&lt;div style=&quot;background:#f0f0f0; border:1px solid #000000; padding-left:10px; width:60%&quot;&gt;


W:\usr\local\mysql\bin>'''mysql -uroot -proot'''<br>
W:\usr\local\mysql\bin&gt;'''mysql -uroot -proot'''&lt;br&gt;
Welcome to the MySQL monitor.  Commands end with ; or \g.<br>
Welcome to the MySQL monitor.  Commands end with ; or \g.&lt;br&gt;
Your MySQL connection id is 216<br>
Your MySQL connection id is 216&lt;br&gt;
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)<br>
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)&lt;br&gt;


Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br>
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.&lt;br&gt;


mysql>
mysql&gt;
</div>
&lt;/div&gt;
</td>
&lt;/td&gt;
</tr>
&lt;/tr&gt;
</table>
&lt;/table&gt;
To create users and set permissions, you must have the necessary permissions to do so. By default, Uniform Server's MySQL has such an account named '''root''' with password root (remember to change this) and all required permissions. It is constrained to run on local host access only.
To create users and set permissions, you must have the necessary permissions to do so. By default, Uniform Server's MySQL has such an account named '''root''' with password root (remember to change this) and all required permissions. It is constrained to run on local host access only.


Line 102: Line 110:


followed by:
followed by:
  '''grant all privileges on mpg3_db.* to mpg3@"localhost" identified by 'mpg3abc';'''
  '''grant all privileges on mpg3_db.* to mpg3@&quot;localhost&quot; identified by 'mpg3abc';'''


* First line creates a database named '''mpg3_db'''. This step can be left out if the database already exists.
* First line creates a database named '''mpg3_db'''. This step can be left out if the database already exists.
Line 108: Line 116:


:* '''grant all privileges on mpg3_db.*'''  Specifies the database (mp3_db) a user will be allowed to access. The '''.*''' indicates that this user is permitted to work with all of the tables within the database mpg_db. (You can limit the user to one table, the name of that table should be specified after the period in place of the asterisk.
:* '''grant all privileges on mpg3_db.*'''  Specifies the database (mp3_db) a user will be allowed to access. The '''.*''' indicates that this user is permitted to work with all of the tables within the database mpg_db. (You can limit the user to one table, the name of that table should be specified after the period in place of the asterisk.
:* '''mpg3@"localhost"''' This sets up the user information. The user named mpg3 is being created. The portion after the '''@''' indicates the host from which this user is allowed to connect. In this case, this user can only connect from the localhost.
:* '''mpg3@&quot;localhost&quot;''' This sets up the user information. The user named mpg3 is being created. The portion after the '''@''' indicates the host from which this user is allowed to connect. In this case, this user can only connect from the localhost.
:* '''mpg3abc''' This is the password to be used by the user. (Always use a password that contains both random alpha and numeric characters.)
:* '''mpg3abc''' This is the password to be used by the user. (Always use a password that contains both random alpha and numeric characters.)


Line 118: Line 126:
'''
'''
followed by:
followed by:
  '''grant all privileges on *.* to mpg4@"localhost" identified by 'mpg4abc';'''
  '''grant all privileges on *.* to mpg4@&quot;localhost&quot; identified by 'mpg4abc';'''


As with the previous example, lets look at the statement piece by piece.
As with the previous example, lets look at the statement piece by piece.


* '''<nowiki>*.*</nowiki>''' This indicates that the user will be permitted to connect to all of the MySQL databases and all of the tables contained in those databases.
* '''&lt;nowiki&gt;*.*&lt;/nowiki&gt;''' This indicates that the user will be permitted to connect to all of the MySQL databases and all of the tables contained in those databases.
* '''mpg4@"%"''' This sets up the user information. The user named mpg4 is being created. This time a host of "%" is used. This indicates that this user may connect to the database from any host or IP number. A more secure way to do this is to specify the IP number of the user, however sometimes this is not possible.
* '''mpg4@&quot;%&quot;''' This sets up the user information. The user named mpg4 is being created. This time a host of &quot;%&quot; is used. This indicates that this user may connect to the database from any host or IP number. A more secure way to do this is to specify the IP number of the user, however sometimes this is not possible.
*''''mpg4abc'''' As in the previous example sets the password.
*''''mpg4abc'''' As in the previous example sets the password.


Line 130: Line 138:
In both of the above examples, we created users with all privileges granted on their respective database(s). If the user is connecting from the Internet or a remote workstation, reduce these privileges or kiss your database good bye. Use the following statement to reduce privileges:
In both of the above examples, we created users with all privileges granted on their respective database(s). If the user is connecting from the Internet or a remote workstation, reduce these privileges or kiss your database good bye. Use the following statement to reduce privileges:


  '''grant select,insert,update,delete,create,drop on mpg3_db.* to mpg3@"%" identified by 'mpg3abc';'''
  '''grant select,insert,update,delete,create,drop on mpg3_db.* to mpg3@&quot;%&quot; identified by 'mpg3abc';'''


With this statement, the user mpg3 is allowed limited access to the database mpg3_db from any host ("%") using the password mpg3abc.
With this statement, the user mpg3 is allowed limited access to the database mpg3_db from any host (&quot;%&quot;) using the password mpg3abc.


The '''grant''' statement specifies that this user is only allowed to run a limited amount of statements on the MySQL server. This user will be allowed to: '''select''' records, '''insert''' records, '''update''' records, '''delete''' records, '''create''' databases, and '''DROP''' (delete) DATABASEs. More importantly, this user is '''not permitted''' to create users and set privileges.
The '''grant''' statement specifies that this user is only allowed to run a limited amount of statements on the MySQL server. This user will be allowed to: '''select''' records, '''insert''' records, '''update''' records, '''delete''' records, '''create''' databases, and '''DROP''' (delete) DATABASEs. More importantly, this user is '''not permitted''' to create users and set privileges.
322

edits