zoukankan      html  css  js  c++  java
  • 设置 Linux 服务器中 MySQL 允许远程访问

    开启 MySQL 远程访问权限: 在linux系统上登陆mysql服务。

    -- root 是用户名
    [root@localhost ~]# mysql -u root -p
    Enter password: --  输入密码

    创建远程连接 MySQL 的用户:

    -- 创建用户、密码及权限范围 第一个 roo t为用户名 @后为适用的主机,‘%’表示所有电脑都可以访问连接,第二个 root 为密码
    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.0.2' IDENTIFIED BY 'root' WITH GRANT OPTION;                 
    Query OK, 0 rows affected (1.57 sec)
    
    -- 立即生效
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    数据库用户操作:

    -- 使用 mysql 库
    mysql> use mysql;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    
    -- 查看用户

      mysql> select host,user from user;
      +-----------+------------------+
      | host      | user             |
      +-----------+------------------+
      | %         | lys              |
      | %         | mcAdmin          |
      | %         | root             |
      | %         | zcbox            |
      | localhost | debian-sys-maint |
      | localhost | mysql.session    |
      | localhost | mysql.sys        |
      | localhost | phpmyadmin       |
      +-----------+------------------+
      8 rows in set (0.00 sec)

      -- 更改用户权限:

      mysql> update user set host = 'localhost' where user = 'mcAdmin';
      Query OK, 1 row affected (0.00 sec)
      Rows matched: 1 Changed: 1 Warnings: 0

      -- 删除用户:  

      mysql> delete from user where user = 'mcAdmin';
      Query OK, 1 row affected (0.00 sec)

      

    -- 立即生效
     mysql> flush privileges;
     Query OK, 0 rows affected (0.00 sec)
    可见user实际上是一个表,对其操作与普通的mysql操作没有什么不同。

    此时旧版的mysql,就已经让数据库可以外部访问了

    但在mysql5.7中,上面操作可能仍然不能让你外部访问本地服务器数据库,因为5.7中MySQL的配置文件里默认也是仅允许本地访问
    所以还要修改MySQL的配置文件
    一般来说在路径/etc/mysql/mysql.conf.d/mysqld.cnf下
    通过vi/vim/gedit等编辑器打开此文件

    注释掉 bind-address          = 127.0.0.1
    然后 sudo service mysql restart 重启mysql

    搞定!

    查看端口: 

    mysql> show global variables like 'port';
    +---------------+-------+
    | Variable_name | Value |
    +---------------+-------+
    | port          | 3306  |
    +---------------+-------+
    1 row in set (0.01 sec)

    貌似还有可能是3306端口的问题,配置文件中也有看到port = 3306 这一行,但是没影响就先不管了;
    遇到了再解决

  • 相关阅读:
    卡尔曼滤波器的简单推导
    data_quick 进度
    面试
    MapServer+TileCache+Apache+Python24 构建KS数据服务器
    PYTHONPATH 可以跨版本 方便使用 (本文为windows方法)转~
    20130923
    20130909
    error C2504 类的多层继承 头文件包含
    int long 等基础类型在不同平台的大小
    mysql python image 图像存储读取
  • 原文地址:https://www.cnblogs.com/wangtong111/p/11201734.html
Copyright © 2011-2022 走看看