Linux下mysql创建用户并设置权限,设置远程连接

为了安全考虑,OneinStack仅允许云主机本机(localhost)连接数据库,如果需要远程连接数据库,需要如下操作:
打开iptables 3306端口

# iptables -I INPUT 4 -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
# service iptables save //保存iptables规则

# iptables -nvL //查看端口开启情况

=======================================================================================
root用户登录mysql   mysql5.7版本使用
mysql>create database SubAccount;
mysql>GRANT ALL PRIVILEGES ON SubAccount.* TO drcloudapi@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;  // *.*表示所有库的所有表
mysql>flush privileges;
mysql>use SubAccount;

=================================================================================

mysql5.7版本password已经改为authentication_string

insert into mysql.user(Host,User,authentication_string) values("%","zizhanghu",password("123456")); //<=5.1版本能用
//GRANT ALL PRIVILEGES ON SubAccount.* TO zizhanghu@"%" IDENTIFIED BY "123456" WITH GRANT OPTION;
//为用户创建一个数据库(SubAccount):
mysql>create database SubAccount;
//授权yanzm用户拥有SubAccount数据库的所有权限(某个数据库的所有权限):
mysql>grant all privileges on SubAccount.* to zizhanghu@'%' identified by '123456';
//刷新系统权限表
mysql>flush privileges;
mysql>use SubAccount;

上一篇:Android按返回键退出程序但不销毁,程序后台保留


下一篇:html 统一资源定位器(url)和url编码