当前位置:asp编程网>技术教程>Database教程>  正文

linux中操作mysql相关命令

2020-04-22 09:17:27   来源:www.aspbc.com   作者:wangsdong   浏览量:2545   收藏
linux上连接上mysql,假设mysql在服务的位置/usr/local/mysql/bin/,假设数据库的用户名为root,密码为root
#cd /usr/local/mysql/bin/
#mysql -uroot -proot

以下是linux中数据库相关的操作
1、远程帐号
a) 允许test用户(密码为123123123,远程的密码不要和root密码一样)远程访问mysql数据库中所有数据库
grant all privileges on *.* to 'test' @'%' identified by '123123123' WITH GRANT OPTION; 
注意:这里的%表示不限连接mysql服务器的客户端ip。如果你要指定连接的客户端ip,需要将%换成ip地址。以下%都是表示不限客户端ip
b) 允许test用户(密码为123123123)远程访问mysql数据库中所有数据库1
grant all privileges on 数据库名1.* to 'test' @'%' identified by '123123123' WITH GRANT OPTION; 
c)允许test用户(密码为123123123)远程访问mysql数据库中所有数据库1中的表1
grant all privileges on 数据库名1.表名1 to 'test' @'%' identified by '123123123' WITH GRANT OPTION; 

2、查看所有库
show databases;

3、创建库
CREATE DATABASE test_db;

4、防火墙
[root@localhost ]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[root@localhost ]# /etc/init.d/iptables save
[root@localhost ]# /etc/init.d/iptables restart

5、权限
授予用户权限:
grant all privileges on 层级 to 用户名@主机  identified by  '密码';

授予test用户全局级全部权限:

grant all privileges on *.* to 'test'@'%' identified by '123123123';

授予test用户针对xsgl数据库全部权限:

grant all privileges on assistant.* to 'test'@'%' identified by '123123123';

删除一个用户权限:(小写)

REVOKE ALL PRIVILEGES FROM 用户名;

撤销test用户的全部权限:
revoke all on *.* from 'test'@'%'; 

关于我们-广告合作-联系我们-积分规则-网站地图

Copyright(C)2013-2017版权所属asp编程网