Adding New User Privileges to MySQL

You can add users two di erent ways: by using GRANT statements or by manipulating the
MySQL grant tables directly. The preferred method is to use GRANT statements, because
they are more concise and less error-prone.

The examples below show how to use the mysql client to set up new users. These examples
assume that privileges are set up according to the defaults described in the previous section.
This means that to make changes, you must be on the same machine where mysqld is
running, you must connect as the MySQL root user, and the root user must have the
insert privilege for the mysql database and the reload administrative privilege. Also, if you
have changed the root user password, you must specify it for the mysql commands below.
You can add new users by issuing GRANT statements:

shell> mysql --user=root mysql
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%"
IDENTIFIED BY 'some_pass' WITH GRANT OPTION;
mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost;
mysql> GRANT USAGE ON *.* TO dummy@localhost;
These GRANT statements set up three new users:

monty A full superuser who can connect to the server from anywhere, but who must use
a password 'some_pass' to do so. Note that we must issue GRANT statements
for both monty@localhost and monty@"%". If we don't add the entry with
localhost, the anonymous user entry for localhost that is created by mysql_
install_db will take precedence when we connect from the local host, because
it has a more speci c Host eld value and thus comes earlier in the user table
sort order.
admin A user who can connect from localhost without a password and who is granted
the reload and process administrative privileges. This allows the user to execute the mysqladmin reload, mysqladmin refresh, and mysqladmin flush-*
commands, as well as mysqladmin processlist .
No database-related privileges are granted. They can be granted later by issuing additional GRANT
statements.

dummy A user who can connect without a password, but only from the local host. The
global privileges are all set to 'N' | the USAGE privilege type allows you to
create a user with no privileges. It is assumed that you will grant databasespeci c privileges later.
You can also add the same user access information directly by issuing INSERT statements
and then telling the server to reload the grant tables

Related Posts:
  • Data Definition Language (DDL) statements? Data Definition Language (DDL) statements  Allow you to define the data structures, such as tables, that make up a database. There are five basic types of DDL statements: CREATE  Allows you to cr… Read More
  • LOAD DATA INFILE statement MySQL LOAD DATA INFILE provides an alternative to INSERT for adding new records to a table. With INSERT, you specify data values directly in the INSERT statement. LOAD DATA INFILE reads the values from a separate datafile.The… Read More
  • SQL inherently SQL, or Structured Query Language, is not really a language. It does not follow all the rules of the typical computer programming language. There are no constructs in SQL to allow decision branches. You can't go to a sp… Read More
  • MySQL Server Performance To make things  easier for administrators. Minimal memory, relatively infrequent MySQL usage: my-small.cnf Minimal memory combined with reliance on MySQL, or larger memory for a multipurpose system: my-medium.… Read More
  • Combined Queries-UNION Mosy SQL queries contain just one SELECT statement that can return data from one table, or several tables using a join. The technique of combining two or more independent queries into a single data set is usually known a… Read More
  • Why NoSQL? Application requirements have fundamentally changed, and traditional RDBMS technology has failed to keep pace. As a result, the use of NoSQL technology is rising rapidly. Massive change is underway, disrupting the databas… Read More
  • What Is a Relational Database? The basic concepts of a relational database are fairly easy to understand. A relational database is a collection of related information that has been organized into structures known as tables. Each table contains rows th… Read More
  • Query Strings Query string data is very easy for the user to alter, because it ’ s visible and editable within the browser ’ s address bar. Therefore, query strings should be used only in situations where sending incorrect data won ’ t co… Read More
  • Linking Affects the Speed of MySQL Most of the following tests are done on Linux with the MySQL benchmarks, but they should give some indication for other operating systems and workloads. You get the fastest executable when you link with -static. On Linux, yo… Read More
  • Data Control Language (DCL) statements ? Data Control Language (DCL) statements  Allow you to change the permissions on database structures. There are two DCL statements: GRANT  Allows you to give another user access to your database st… Read More
  • Maximum Performance from MySQL Optimization is a complicated task because it ultimately requires understanding of the whole system. While it may be possible to do some local optimizations with small knowledge of your system/application, the more optimal y… Read More
  • Web-Based MySQL Administration Web-Based MySQL Administration At http://phpwizard.net/phpMyAdmin you will find a PHP Web application that can help you manage MySQL. It enables you to manage a MySQL database using a browser and makes administrative work… Read More
  • Data Manipulation Language (DML) statements ? Data Manipulation Language (DML) statements  Allow you to modify the contents of tables. There are three DML statements: INSERT  Allows you to add rows to a table. UPDATE  Allows yo… Read More
  • Conditional Functions mysql The IF() Function The IF() function provides a way to return a value based on a condition within a query. The first argument is a condition that is evaluated for each row of the query. The value in the second is return… Read More
  • Running MySQL on Windows MySQL supports TCP/IP on all Windows platforms and named pipes on NT. The defaultis to use named pipes for local connections on NT and TCP/IP for all other cases if theclient has TCP/IP installed. The host name speci es whic… Read More