Ubuntu 16.04搭建MySQL数据库并设置可远程访问

安装 MySQL

# 更新源
sudo apt-get update
# 安装服务器端,安装过程中会要求输入 root 密码
sudo apt-get install mysql-server
# 安装客户端
sudo apt-get install mysql-client
# 查看是否安装成功
sudo netstat -tap | grep mysql

设置可远程访问

  1. 修改配置文件
    # 将bind-address = 127.0.0.1注释
    sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf  
    
  2. 修改用户权限
    1. 登录 MySQL
    2. 执行下面语句
      # 添加远程 root 登录权限,password 为 你的登录密码
      grant all on *.* to root@'%' identified by 'password';
      # 刷新
      flush privileges;
      
  3. 重启 MySQL 服务

猜你喜欢

转载自blog.csdn.net/TalonZhang/article/details/85058525