时间:2021-07-01 10:21:17 帮助过:21人阅读
- <code>
- mysql> select USER();
- +----------------+
- | USER() |
- +----------------+
- | root@localhost |
- +----------------+
- 1 row in set (0.00 sec)
- </code>
- <code>mysql5以前版本直接使用 INSERT 向 mysql 表中插入mysql用户了,mysql5之后不可以这样操作
- </code>
- <code>mysql> insert into mysql.user(Host,User,Password) values(‘localhost‘,‘test_user‘,password(‘123123‘));
- ERROR 1062 (23000): Duplicate entry ‘localhost-test_user‘ for key ‘PRIMARY‘
- </code>
- <code>增加用户 {授予用户指定数据表权限 [使用 GRANT 命令 对用户进行相应授权]}
- </code>
- <code>mysql> GRANT all privileges ON table1.* TO
- ‘test_user‘@‘localhost‘ IDENTIFIED BY ‘123123‘ WITH GRANT OPTION;
- Query OK, 0 rows affected (0.02 sec)
- </code>
- <code>ALL PRIVILEGES 是表示所有权限,也可以使用 select、update 等权限
- *.\ 中前面的*号用来指定数据库名,后面的*号用来指定表名
- TO 表示将权限赋予某个用户
- ON 用来指定权限针对哪些库和表
- ‘test_user‘@‘localhost‘ 表示test_user用户,@后面接限制的主机,可以是IP、IP段、域名以及%,%表示任何地方
- WITH GRANT OPTION 这个选项表示该用户可以将自己拥有的权限授权给别人
- 需要刷新系统权限表[flush privilege] 该用户才能生效登录
- </code>
- <code>mysql> flush privileges;
- </code>
- <code>mysql> drop user ‘test_user‘@‘localhost‘;
- </code>
- <code>mysql> SHOW GRANTS;
- +----------------------------------------------------------------------------------------------------------------------------------------+
- | Grants for root@localhost |
- +----------------------------------------------------------------------------------------------------------------------------------------+
- | GRANT ALL PRIVILEGES ON *.* TO ‘root‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1‘ WITH GRANT OPTION |
- | GRANT PROXY ON ‘‘@‘‘ TO ‘root‘@‘localhost‘ WITH GRANT OPTION |
- +----------------------------------------------------------------------------------------------------------------------------------------+
- </code>
- <code>mysql> show grants for ‘test_user‘@‘localhost‘
- +------------------------------------------------------------------------------------------------------------+
- | Grants for test_user@localhost |
- +------------------------------------------------------------------------------------------------------------+
- | GRANT USAGE ON *.* TO ‘test_user‘@‘localhost‘ IDENTIFIED BY PASSWORD ‘\*E56A114692FE0DE073F9A1DD68A00EEB9703F3F1‘ |
- | GRANT ALL PRIVILEGES ON table1.* TO ‘test_user‘@‘localhost‘ WITH GRANT OPTION |
- +------------------------------------------------------------------------------------------------------------+
- </code>
- <code>mysql> rename user ‘test_user‘@‘localhost‘ to ‘bb‘@‘localhost‘;
- </code>
- <code>1.用set password命令
- </code>
- <code>mysql> SET PASSWORD FOR ‘test_user‘@‘localhost‘ = PASSWORD(‘123456‘);
- </code>
- <code>2.用 mysqladmin [进入bin目录]
- 备注:{格式: mysqladmin -u用户名 -p旧密码 password 新密码]
- </code>
- <code>/usr/bin$ mysqladmin -utest_user -p123456 password 123123
- mysqladmin: Can‘t turn off logging; error: ‘Access denied; you need (at least one of) the SUPER privilege(s) for this operation‘
- </code>
- <code>3.用 update 直接编辑 user 表
- </code>
- <code>mysql> use mysql
- Reading table information for completion of table and column names
- You can turn off this feature to get a quicker startup with -A
- Database changed
- mysql> update user set PASSWORD = PASSWORD(‘123123‘) where user = ‘test_user‘;
- Query OK, 1 row affected (0.04 sec)
- Rows matched: 1 Changed: 1 Warnings: 0
- </code>
Mysql用户管理相关
标签:mysq 地方 需要 增加用户 sel try log 生效 ica