Ubuntu Server 16.04 安裝MySQL並設定遠端存取

來源:互聯網
上載者:User

Ubuntu Server 16.04 安裝MySQL並設定遠端存取

一、Ubuntu Server 16.04 安裝MySQL

1. 使用root帳號

sudo apt-get install mysql-server
apt-get isntall mysql-client
apt-get install libmysqlclient-dev

如果中途有問題就執行以下 apt-get update

2. 以上3個軟體包安裝完成後,使用如下命令查詢是否安裝成功:

sudo netstat -tap | grep mysql

查詢結果如所示,表示安裝成功。

root@ubuntu:~# netstat -tap | grep mysql
tcp6      0      0 [::]:mysql              [::]:*                  LISTEN      7510/mysqld   
root@ubuntu:~#

二、設定mysql遠端存取

1. 編輯mysql設定檔,把其中bind-address = 127.0.0.1注釋了

vi /etc/mysql/my.cnf

2. 使用root進入mysql命令列,執行如下2個命令,樣本中mysql的root帳號密碼:root

root@ubuntu:~# mysql -uroot -proot

mysql>grant all on *.* to root@'%' identified by 'root' with grand option;

 *.*:第一個*代表資料庫名;第二個*代表表名。這裡的意思是所有資料庫裡的所有表都授權給使用者。root:授予root帳號。“%”:表示授權的使用者IP可以指定,這裡代表任意的IP地址都能訪問MySQL資料庫。“password”:分配帳號對應的密碼,這裡密碼自己替換成你的  mysql root帳號  密碼。

mysql>flush privileges;

重新整理許可權資訊,也即是讓我們所作的設定馬上生效。

3. 重啟mysql

/etc/init.d/mysql restart

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.