-----创建用户
CREATE USER
语法:
CREATE USER'username'@'host' IDENTIFIED BY 'password';
例子: CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
CREATE USER 'pig'@'192.168.1.101_' IDENDIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '123456';
CREATE USER 'pig'@'%' IDENTIFIED BY '';
CREATE USER 'pig'@'%';
实例1:
mysql> create user jss;
这样创建的用户,可以从任意安装了mysql客户端,并能够访问目标服务器的机器上创建连接,无须密码.例如,从ip:10.0.0.99的客户端执行连接:
mysql -ujss -h 172.16.1.110
查看该用户:
mysql> select user,host,password from user where user='jss';
SELECT USER(); //显示当前用户
--------授权
授权法:mysql的root用户默认情况下只能在本地登陆,不能远程,若远程连接,需要授权:
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
mysql>FLUSH PRIVILEGES;
('root'@'%',指定root用户可以在任意一台计算机上连接数据库服务器,若要指定特定的计算机,可将%替换为特定的IP)