How to add a user to mysql database

First, log on to the MySQL server as root.

$ Mysql -u root -p

When authentication prompt appears, enter the MySQL root account password.

Creating a MySQL user

create a user name and password are "myuser" and "mypassword" users use the following command.

mysql> CREATE USER 'myuser' @ 'localhost' IDENTIFIED BY 'mypassword';

Once the user is created, including encrypted passwords, permissions and resource limits, including all account details will be stored in a table named user, the this table is present in this special mysql database.

Run the following command to verify the account is successfully created

mysql> SELECT host, user, password FROM mysql.user WHERE user = 'myuser';

gives MySQL user rights

a new MySQL user does not have any access rights, which means that you can not in MySQL any operation database. You have to give users the necessary permissions. The following are some of the privileges available:

ALL: all available permissions
CREATE: create database tables and indexes
LOCK_TABLES: Lock table
ALTER: modify the table
DELETE: delete the table
INSERT: insert table or column
SELECT: data retrieval table or column
CREATE_VIEW: Creating view
SHOW_DATABASES:


Run the following command gives "myuser" user specific permissions.

mysql> GRANT <privileges> ON < database> <table> TO 'myuser' @ 'localhost';.

the above command, <privileges> represents a comma-separated list of permissions. If you want to privileges granted to any database (or table), then use an asterisk (*) instead of the name of the database (or table).

For example, given for all database / table CREATE and INSERT privileges:

MySQL> the GRANT CREATE, INSERT the ON * * the TO 'myuser' @ 'localhost';.

Validate a full authority users assigned:

MySQL> SHOW GRANTS the FOR 'myuser' @ ' localhost ';

all of the rights granted to all database / table:

MySQL> GRANT ALL ON * * the tO.' myuser '@' localhost ';

you can also delete the existing user permissions. Repealing the following command "myuser" account existing permissions:

. MySQL> REVOKE <privileges> the ON <Database> <Table> the FROM 'myuser' @ 'localhost';

For the user to add resource limits

in MySQL, you can set the MySQL resource usage limits for individual users. Available resource constraints as follows:

MAX_QUERIES_PER_HOUR: the maximum allowable number of requests per hour
MAX_UPDATES_PER_HOUR: maximum allowable number of updates per hour
MAX_CONNECTIONS_PER_HOUR: maximum allowed connections per hour (LCTT translation: with the MySQL global variables: max_user_connections common user to determine the number of simultaneous database connections) Number of
MAX_USER_CONNECTIONS: the amount of connections to the server at the same time

using the following command to add a resource limit "myuser" Account :

. MySQL> the GRANT the USAGE the oN <Database> <Table> the tO 'myuser' @ 'localhost' the WITH <resource-limits>;

the <resource-limits> you can specify a plurality of spaces separated by the resource use restriction.

For example, increasing the MAXQUERIESPERHOUR and MAXCONNECTIONSPERHOUR resource constraints:

MySQL> the GRANT the USAGE the ON * * the TO 'myuser' @ 'localhost' the WITH MAX_QUERIES_PER_HOUR 30 MAX_CONNECTIONS_PER_HOUR. 6;.

Verify the user's resource limits:

MySQL> SHOW GRANTS the FOR 'myuser' @ 'localhost;

Create and set up a MySQL user last an important step:

MySQL> FLUSH PRIVILEGES;

this way the change will take effect. Now MySQL user account can use.

Guess you like

Origin www.cnblogs.com/lijunji/p/11520247.html