Method to add username and password in mysql: execute [insert into mysql.user(Host,User,Password) values("localhost","username",password("password"));】 statement.
Reminder:
This operation is performed under the WIN command prompt, and the same applies to phpMyAdmin.
User: phplamp User database: phplampDB
(Recommended tutorial: mysql tutorial)
The specific method is as follows:
1. Create a new user
//登录MYSQL @>mysql -u root -p @>密码 //创建用户 mysql> insert into mysql.user(Host,User,Password) values("localhost","phplamp",password("1234")); //刷新系统权限表 mysql>flush privileges;
This creates a user named: phplamp with a password of: 1234.
Then log in.
mysql>exit; @>mysql -u phplamp -p @>输入密码 mysql>登录成功
2. Authorize the user
//登录MYSQL(有ROOT权限)。我里我以ROOT身份登录. @>mysql -u root -p @>密码 //首先为用户创建一个数据库(phplampDB) mysql>create database phplampDB; //授权phplamp用户拥有phplamp数据库的所有权限。 >grant all privileges on phplampDB.* to phplamp@localhost identified by '1234'; //刷新系统权限表 mysql>flush privileges; mysql>其它操作 /* 如果想指定部分权限给一用户,可以这样来写: mysql>grant select,update on phplampDB.* to phplamp@localhost identified by '1234'; //刷新系统权限表。 mysql>flush privileges; */
3. Delete the user
@>mysql -u root -p @>密码 mysql>DELETE FROM user WHERE User="phplamp" and Host="localhost"; mysql>flush privileges; //删除用户的数据库 mysql>drop database phplampDB;
4. Modify the specified user password
@>mysql -u root -p @>密码 mysql>update mysql.user set password=password('新密码') where User="phplamp" and Host="localhost"; mysql>flush privileges;
Related recommendations: php training
The above is the detailed content of How to add username and password in mysql. For more information, please follow other related articles on the PHP Chinese website!