zoukankan      html  css  js  c++  java
  • 远程操作虚拟机中的mysql服务器

    一、查看系统端口号开发状态:

    查看 服务器端口号:

    grep servicename /etc/services:

    netstat -an | grep servicename

    首先需要开启3306端口:

    二、开启虚拟机中的mysql数据库(3306端口):

    1、第一步查看虚拟机中的防火墙是否开启:

    systemctl status firewalld

    2、第二部:如果没有启用:使用如下命令启用防火墙:(如果已经启动则跳过这一步)

    service  firewalld start

    3、第三步:使用如下命令启用3306端口:

    a:firewall-cmd --zone=public --add-port=3306/tcp --permanent

    b:firewall-cmd --reload

    4、第四步:在cmd中输入:telnet ip 3306查看是否已经开放。

    三、授权mysql对任意的ip地址都可以访问:

    1、进入远程服务器终端关闭mysql:--->service mysql start

    2、mysql执行屏蔽权限命令:--->mysqld_safe --skip-grant-table

    3、当屏幕出现:Starting demo from ...时,新开其一个终端输入:-->mysql -u mywaf -p mywaf

    4、切换到mysql数据库:-->use mysql

    5、SELECT host ,user from user;

    6、授权任何IP都可以访问该数据库:-->UPDATE user set host=’%’ where user=’root’;

    7、刷新:-->FLUSH PRIVILEGES;

    8、立刻q

    9、重新启动mysql服务器:service mysql start;

     三、授权mysql对特定的ip地址可以访问:

    1-5步同二、

    4、授权用户名为:myuser,ip10.20.80.132的主机连接到mysql服务器,并使用“123456789”作为密码

    命令如下 :--> GRANT all privileges on *.* to myuser@10.20.80.132 identified by ‘123456789’ with grant option;

    6-9步同二、

    四、python连接mysql数据库:

     

    db=pymysql.connect("192.168.26.211","root","mywaf","mywaf",port=3306,charset="utf8")

     

    Connect(“ip”,”密码”,“root”,“密码”,“端口”,“字符编码”)

     

    使用如下命令:查询数据库中mywaf数据库中alarms表中的最后一个记录的内容,

     

    select id,action_id,rule_id,response_code,unique_id, msg_id,severity_id,tag_id from alarms order by id desc limit 0,1;

     

    select 要查看找的字段 from 数据表 order by id desc limit 0,1;  --->查找最新插入的一条记录

     

    select 要查看找的字段 from 数据表 order by id desc limit 0,10;  ---> 查找最新插入的10条记录

     

    select column_name from information_schema.COLUMNS where table_name='表名称'  --->查询该表有那些字段,以便进行条件查询

     

     

     

    请尊重笔者的劳动成果哦,转载请说明出处哦
  • 相关阅读:
    construction of tuples containing 0 or 1 items
    globals()
    __new__
    ubuntu系统安装mysql登陆提示 解决Mysql ERROR 1045 (28000): Access denied for user 'root'@'localhost'问题
    ubuntu系统更新源
    Python Web开发问题收集(二)
    linux后台执行./run.py提示python syntax error near unexpected token `('
    linux下执行scrapy的爬虫定时任务
    ubuntu系统中crontab的使用介绍
    JMeter BeanShell断言使用
  • 原文地址:https://www.cnblogs.com/gufengchen/p/13865903.html
Copyright © 2011-2022 走看看