MySQL: Difference between revisions

From vwiki
Jump to navigation Jump to search
(Initial creation)
 
m (Added "User Accounts")
Line 1: Line 1:
== User Accounts ==
=== Create Users ===
To give full privileges to a user coming from any location use;
* <code> GRANT ALL PRIVILEGES on <database>.* to '<user>'@'%' identified by '<password>' with grant option; </code>
=== Display Users ===
To display all configured users;
* <code> <nowiki> SELECT CONCAT('SHOW GRANTS FOR \'', user ,'\'@\'', host, '\';') FROM mysql.user </nowiki></code>
Then use the displayed lines to see the detail of each user
== Data Types ==
== Data Types ==
=== IP Addresses ===
=== IP Addresses ===

Revision as of 11:58, 22 December 2009

User Accounts

Create Users

To give full privileges to a user coming from any location use;

  • GRANT ALL PRIVILEGES on <database>.* to '<user>'@'%' identified by '<password>' with grant option;

Display Users

To display all configured users;

  • SELECT CONCAT('SHOW GRANTS FOR \'', user ,'\'@\'', host, '\';') FROM mysql.user

Then use the displayed lines to see the detail of each user

Data Types

IP Addresses

IP addresses are most efficiently stored as an UNSIGNED INT, though obviously this isn't particularly human readable. MySQL will do the conversion between INT and dotted quad using the INET_ATON and INET_NTOA functions. For example;

  • SELECT INET_NTOA(ip) from ips;
  • INSERT INTO ips SET ip=INET_ATON('10.1.2.3');

Alternatively, use VARCHAR(15) to store as text.