1,查询mysql 数据库已经存在的用户:
SELECT USER,HOST FROM MYSQL.USER;
2,创建mysql 用户:
CREATE USER 'USERNAME'@'HOST' IDENTIFIED BY 'PASSWORD';
CREATE USER 'chris'@'%' IDENTIFIED BY '123456';CREATE USER 'lily'@'localhost' IDENTIFIED BY '123456';CREATE USER 'Tom'@'10.99.10.2' IDENTIFIED BY '123456';
USERNAME:用户名 HOST:主机,PASSWORD:密码
localhost:只可以本地登陆
%:本地登陆,远程登陆
10.99.10.2:指定登陆的ip
3, 删除mysql 用户:
DROP USER 'USERNAME'@'HOST';
DROP USER 'chris'@'localhost';
4,用户授权:
1,先创建测试数据库
CREATE DATABASE testDB;
GRANT ALL ON *.* TO 'chris'@'%';
5,修改Host 可以远程登陆
SET SQL_SAFE_UPDATES = 0 update MYSQL.user set host = '%' where user = 'root'
SET SQL_SAFE_UPDATES = 0 的作用是为了修改mysql 的安全模式,因为
在使用mysql执行update的时候,如果不是用主键当where语句,会报如下错误,使用主键用于where语句中正常。
异常内容:Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode, toggle the option in Preferences -> SQL Queries and reconnect.