1.新建普通用戶mysql
--create語句sql
mysql> create user 'test1'@'localhost' identified by 'test1';vim
--使用insert插入ide
mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values('localhost','test2',password('test2'),'','','');rest
mysql> flush privileges;ip
--使用grant語句ssl
mysql> grant select on *.* to 'test3'@'localhost' identified by 'test3';ci
mysql> flush privileges;it
2.刪除普通用戶table
--drop刪除
mysql> drop user 'test1'@'localhost';
--使用delete從表中刪除
mysql> delete from mysql.user where host='localhost' and user='test2';
mysql> flush privileges;
3.root修改密碼
----root修改root密碼
--mysqladmin修改
[root@test ~]# mysqladmin -uroot -p password
Enter password:
New password:
Confirm new password:
--登錄後使用update修改
mysql> update mysql.user set password=password('root') where host='localhost' and user='root';
mysql> flush privileges;
--登錄後使用set修改
mysql> set password=password('root')
mysql> flush privileges;
----root修改普通用戶密碼
--set語句
mysql> set password for 'test3'@'localhost'=password('test3');
--update更新mysql.user表
mysql> update mysql.user set password=password('test3') where host='localhost' and user='test3';
mysql> flush privileges;
--grant語句
mysql> grant select on *.* to 'test3'@'localhost' identified by 'test3';
grant修改密碼後,以前對用戶使用舊密碼的受權還在
4.普通用戶本身修改密碼
mysql> set password=password('test4');
普通用戶通常不能使用mysqladmin
5.root密碼丟失
[root@test ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@test ~]# /etc/init.d/mysqld restart
[root@test ~]# mysql
mysql>
mysql> update mysql.user set password=password('root') where host='localhost' and user='root';
mysql> flush privileges;
注:使用mysql-5.5.30