標籤:localhost password identified insert create
1.建立普通使用者
--create語句
mysql> create user ‘test1‘@‘localhost‘ identified by ‘test1‘;
--使用insert插入
mysql> insert into mysql.user(Host,User,Password,ssl_cipher,x509_issuer,x509_subject) values(‘localhost‘,‘test2‘,password(‘test2‘),‘‘,‘‘,‘‘);
mysql> flush privileges;
--使用grant語句
mysql> grant select on *.* to ‘test3‘@‘localhost‘ identified by ‘test3‘;
mysql> flush privileges;
2.刪除普通使用者
--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修改
[[email protected] ~]# 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密碼丟失
[[email protected] ~]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[[email protected] ~]# /etc/init.d/mysqld restart
[[email protected] ~]# mysql
mysql>
mysql> update mysql.user set password=password(‘root‘) where host=‘localhost‘ and user=‘root‘;
mysql> flush privileges;
注:使用mysql-5.5.30
本文出自 “風行SUI” 部落格,請務必保留此出處http://8722413.blog.51cto.com/8712413/1542400