My MySQL is installed in c: \ mysql
I. Change the password
Method 1:
1. the root account has no password before the change.
C: \ mysql \ bin> mysqladmin-u Root Password "your password"
2. Change the password of the root user if it is 123456.
C: \ mysql \ bin> mysqladmin-u root-p123456 password "your password"
Note: The changed password cannot be enclosed in single quotes. It can be enclosed in double quotes or no quotation marks.
Method 2:
1. c: \ mysql \ bin> mysql-uroot-P password to log on as root
2. mysql> use MySQL to select a database
3. mysql> Update user SET Password = PASSWORD ('your password') where user = 'root ';
4. mysqlflush privileges; reload the permission table
Ii. user permission settings
1. Log On As root (or other authorized users)
2. The following command creates a test user with the password test and can only operate on the picture database.
Mysql> grant all on picture. * To test identified by "test ";
The syntax of the grant statement looks like this:
Grant privileges (columns) on what to user identified by "password" with grant option
To use this statement, you must enter the following parts:
Privileges grants permissions to users. The following table lists the permission specifiers that can be used for grant statements:
Operation permitted by the permission specified character
Alter table and Index
Create Database and table Creation
Delete Delete existing records in the table
Drop discard (delete) databases and tables
Create or discard an index
Insert Insert a new row into the table
Reference unused
Select to retrieve records in a table
Update modify existing table records
File: reads or writes files on the server.
Process: View information about the thread executed on the server or kill the thread.
Reload: Reload the authorization table or clear logs, host caches, or table caches.
Shutdown the server
All; All privileges Synonyms
Usage special "no permission" permission
The table above shows that the permission specifiers in the first group apply to databases, tables, and columns, and the second group manages permissions. Generally, these are relatively strictly authorized because they allow users to affect server operations. The third group has special permissions. "All" means "All Permissions", and "uasge" means "no Permissions", that is, creating users, but not granting permissions.
Columns permission is optional, and you can only set column-specific permissions. If the command has more than one column, separate them with commas.
What permission usage level. Permissions Can be global (applicable to all databases and tables), specific databases (applicable to all tables in a database), or specific tables. You can specify a columns statement to indicate that the permission is column-specific.
The user authorized by the user, which consists of a user name and a host name. In MySQL, you not only specify who can connect, but also where to connect. This allows two users with the same name to connect from different places. MySQL allows you to differentiate them and grant them permissions independently. A user name in MySQL is the user name specified when you connect to the server. It does not need to be associated with your UNIX or Windows Name. By default, if you do not specify a specific name, the customer program uses your login name as the MySQL user name. This is just an agreement. You can change the name to nobody in the authorization table, and then use the nobody connection to perform operations that require superuser permissions.
Password: Optional. If you do not specify the identified by clause for a new user, the user is not assigned a password (Insecure ). For existing users, any password you specify will replace the old password. If you do not specify a password, the old password remains unchanged. When you use identified by, the password string uses the literal meaning of the password, and grant will encode the password for you, do not use the password () function like set password.
The with grant option clause is optional. If you include it, you can grant permissions to other users through the grant statement. You can use this clause to grant permissions to other users.
Note: The username, password, database, and table names are case sensitive in the authorization table records, and the host name and column name are not.
Generally, you can identify the types of grant statements by asking a few simple questions:
Who can connect from there?
What level of permissions should users have and what do they apply?
Should the user be allowed to manage permissions?
The following are some examples.
1.1 who can connect and connect from there?
You can allow a user to connect from a specific host or a series of hosts. There is one extreme: If you know that a demotion is connected from a host, you can limit the permissions to a single host:
Grant all on samp_db. * to Boris @ localhost identified by "Ruby"
Grant all on samp_db. * To fred@res.mars.com identified by "quartz"
(Samp_db. * indicates "all tables in the samp_db database.) Another extreme is that you may have a user max that is frequently traveling and needs to be connected from hosts around the world. In this case, you can allow him to connect from anywhere:
Grant all on samp_db. * To Max @ % identified by "diamond"
The "%" character acts as a wildcard and matches the like pattern. In the preceding statement, it means "any host ". So Max and Max @ % are equivalent. This is the easiest way to build a user, but it is also the least secure.
You can allow a user to access from a restricted host set. For example, to allow Mary to be connected from any host in the snake.net domain, use the following identifier:
Grant all on samp_db. * to Mary @ .snke.net identified by "quartz ";
If you like, the host part of the User Identifier can be specified by an IP address instead of a host name. You can specify an IP address or an address that contains a pattern character. In addition, from MySQL 3.23, you can also specify an IP number with a network mask indicating the number of digits used for the network number:
Grant all on samp_db. * To boris@192.168.128.3 identified by "Ruby"
Grant all on samp_db. * To fred@192.168.128. % identified by "quartz"
Grant all on samp_db. * To rex@192.168.128.0/17 identified by "Ruby"
The first example indicates that the user can connect to a specific host, and the second specifies the IP Mode for the class C subnet 192.168.128. In the third statement, 192.168.128.0/17: specify a 17-bit network number and match the IP address with the header 192.168.128.
1.2 What level of permissions should users have and what should they apply?
You can grant different levels of permissions. Global permissions are the most powerful because they apply to any database. To make Etel a Super User who can do anything, including authorizing other users, issue the following statement:
Grant all on *. * To Etel @ localhost identified by "coffee" with grant option
*. * In the on Clause indicates "all databases and all tables ". For security considerations, we specify that Etel can only be connected locally. It is usually wise to restrict the host that a Super User can connect to because it limits the host that tries to crack the password.
Some permissions (file, process, reload, and shutdown) are administrative permissions and can only be authorized with the "on *. *" Global permissions. If you want to, you can grant these permissions without authorizing database permissions. For example, if the following statement sets a flush user, it can only issue flush statements. This may be useful when you need to execute management scripts such as clearing logs:
Grant reload on *. * To flushl @ localhost identified by "flushpass"
Generally, you want to authorize management permissions, because users with these permissions can affect the operations on your servers.
Database-level permissions apply to all tables in a specific database. They can be granted by using the on db_name. * clause:
Grant all on samp_db to bill@racer.snake.net indetified by "rock" Grant select on samp_db to ro_user @ % indetified by "rock"
The first statement grants permissions to all tables in the samp_db database to Bill, and the second statement creates a user ro_user (read-only user) that strictly restricts access, which can only access all tables in the samp_db database, but only read, that is, you can only issue select statements.
You can list a series of permissions granted at the same time. For example, if you want to allow users to read and modify the content of an existing database but cannot create or delete a new table, grant the following permissions:
Grant select, insert, delete, update on samp_db to bill@snake.net indetified by "rock"
For more refined access control, you can grant permissions on each table or even on each column of the table. When you want to hide a part of a table from a user, or you want a user to modify only specific columns, column-specific permissions are very useful. For example:
Grant select on samp_db.member to Bill @ localhost indetified by "rock"
Grant Update (expiration) on samp_db. member to Bill @ localhost
The first statement grants the read permission to the entire Member table and sets a password. The second statement adds the update permission when only the expiration column is applied. You do not need to specify a password because the first statement has already been specified.
If you want to grant permissions to multiple columns, specify a list separated by commas. For example, to add the update permission for the address field of the member table to the assistant user, use the following statement to add the new permission to the user's existing permissions:
Grant Update (street, city, state, zip) on samp_db to assistant @ localhost
1.3 Should users be permitted to manage permissions?
You can allow a database owner to control database access by granting all database owner permissions. During authorization, specify with grant option. For example, if you want Alicia to connect to any host in the big.corp.com domain and have the Administrator permission for all tables in the sales database, you can use the following grant statement:
Grant all on sales. * to Alicia @ % .big.corp.com indetified by "AppleJuice" with grant option
In effect, the with grant option clause allows you to grant the Access Authorization right to another user. Note that two users with the grant permission can authorize each other. If you only grant select permission to the first user and grant select permission to the other user, the second user can be the first user more powerful ".
2. revoke permissions and delete users
To cancel a user's permissions, use the revoke statement. The syntax of revoke is very similar to the grant statement, except that it is replaced by from without the indetifed by and with grant option clauses:
Revoke privileges (columns) on what from user
The user part must match the user part of the user you want to revoke permission from the original grant statement. Privileges does not need to be matched. You can use the grant statement to grant permissions, and then use the revoke statement to revoke only some permissions.
The revoke statement only deletes permissions, but does not delete users. Even if you revoke all permissions, the user records in the User table are retained, which means that the user can still connect to the server. To completely delete a user, you must use a delete statement to explicitly delete user records from the user table:
% Mysql-u root mysqlmysql> Delete from user-> where user = "user_name" and host = "host_name"; mysql> flush privileges;
The delete statement deletes user records, while the flush statement tells the server to overload the authorization table. (When you use the grant and revoke statements, the table is automatically reloaded, but you do not modify the authorization table directly .)