1. 程式人生 > >Ubuntu 16.04搭建MySQL資料庫並設定可遠端訪問

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 [email protected]'%' identified by 'password';
      # 重新整理
      flush privileges;
      
  3. 重啟 MySQL 服務