zoukankan      html  css  js  c++  java
  • ubuntu18.04安装mysql5.7以及远程连接

    一、安装mysql

    1、安装mysql

    sudo apt-get install mysql-server

    此外还能安装mysql-workbench

    sudo apt-get install mysql-workbench

    2、安装之后查看默认的用户名和密码

    sudo cat /etc/mysql/debian.cnf

    3、用上述用户名和密码登录mysql

     mysql -u debian-sys-maint -p

    然后回车,输入上述密码进行登录

     

    4、修改默认密码

    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 user,plugin from user;

     

    mysql> update user set authentication_string=password('这里输入要设置的新密码'),plugin='mysql_native_password' where user='root';

    刚才就是为root用户设置的密码,以后我们就可以用root用户加上设置的密码登录mysql

    刷新数据库,退出:

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exti;

    到此就可以使用root用户和所设置的密码进行登录mysql数据了

     

    二、远程主机连接mysql数据库

    1、进入mysql的配置文件

    sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

    进入配置文件后输入 i 进入插入模式,然后注释下面这一行(还可把127.0.0.1改为0.0.0.0)

     

     注释之后按Esc返回查看模式,按shift + : ,然后输入 wq 进行保存退出

     重启数据库

    sudo service mysql start

    以上是相关配置,如果想进行远程连接还需要mysql的相关授权:

    登录mysql数据库:

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '这里填写登录密码' WITH GRANT OPTION;
    Query OK, 0 rows affected, 1 warning (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> exit;
    Bye

    到此我们就可以远程连接数据库了,输入ifconfig查看

     

    打开window下的navicat进行远程登录

  • 相关阅读:
    linux:yum
    python:公共操作
    python 控制流程
    linux:lamp环境
    linux:nginx
    深圳:永安在线-安全
    linux:mysql
    linux:shell
    linux:项目上线
    linux:权限管理
  • 原文地址:https://www.cnblogs.com/zh-xiaoyuan/p/13384524.html
Copyright © 2011-2022 走看看