Ubuntu16.04安裝MySQL5.7
阿新 • • 發佈:2019-02-12
安裝主程式
主程式安裝就我知道有兩種方式:
- 使用apt-get全自動安裝
# 安裝命令
apt-get install mysql-server
# 安裝過程中需要輸入mysql的root密碼
- 使用dpkg手動安裝依賴包
# 1. 下載安裝包
# 我測試過程中下載的是:mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar
# 國內映象站:http://mirrors.sohu.com/mysql/MySQL-5.7/
wget http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar
# 2. 解壓安裝包
# 解壓後將出現:
# libmysqlclient20_5.7.16-1ubuntu16.04_amd64.deb
# mysql-common_5.7.16-1ubuntu16.04_amd64.deb
# mysql-community-source_5.7.16-1ubuntu16.04_amd64.deb
# mysql-testsuite_5.7.16-1ubuntu16.04_amd64.deb
# libmysqlclient-dev_5.7.16-1ubuntu16.04_amd64.deb
# mysql-community_5.7.16-1ubuntu16.04_amd64.changes
# mysql-community-test_5.7.16-1ubuntu16.04_amd64.deb
# libmysqld-dev_5.7.16-1ubuntu16.04_amd64.deb
# mysql-community-client_5.7.16-1ubuntu16.04_amd64.deb
# mysql-server_5.7.16-1ubuntu16.04_amd64.deb
# mysql-client_5.7.16-1ubuntu16.04_amd64.deb
# mysql-community-server_5.7.16-1ubuntu16.04_amd64.deb
tar -xvf ../mysql-server_5.7.16-1ubuntu16.04_amd64.deb-bundle.tar -C ./
# 3. 使用dpkg安裝依賴包
dpkg -i mysql-common_5.7.16-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient20_5.7.17-1ubuntu16.04_amd64.deb
dpkg -i libmysqlclient-dev_5.7.17-1ubuntu16.04_amd64.deb
dpkg -i libmysqld-dev_5.7.17-1ubuntu16.04_amd64.deb
# 上面四個包安裝應該都沒有什麼問題,接下來安裝的包將會丟擲缺少依賴包的錯誤
# 所缺包名當時搞忘了記下來,請仔細看一下錯誤資訊,然後使用apt-get安裝一下即可
dpkg -i mysql-community-client_5.7.17-1ubuntu16.04_amd64.deb
dpkg -i mysql-client_5.7.17-1ubuntu16.04_amd64.deb
dpkg -i mysql-community-source_5.7.17-1ubuntu16.04_amd64.deb
# 接下來我們需要安裝mysql-community-server包了,安裝之前還需要按照一個依賴包:libmecab2
apt-get install libmecab2
dpkg -i mysql-community-server_5.7.17-1ubuntu16.04_amd64.deb
## 安裝過程中需要輸入mysql的root密碼
至此,我們已經完成了主程式安裝,並可以在本機使用mysql -u root -p
進行登入資料庫了。
開放遠端訪問
- 開啟root使用者的全稱訪問許可權
- 修改資料庫中user的host
sh
# 使用mysql -u root -p登入到資料庫,然後依次執行下面語句
# xxxxxx表示root使用者的密碼
use mysql;
update user set host = '%' where user ='root';
grant all privileges on *.* to 'root'@'%' identified by 'xxxxxx';
flush privileges;
- 修改my.conf的中的ip繫結
sh
# 進入編輯/etc/mysql/mysql.conf.d/mysqld.conf
vi /etc/mysql/mysql.conf.d/mysqld.conf
# 修改ip繫結
# 原始檔中為:
bind-address 127.0.0.1
# 將其修改為:
bind-address 0.0.0.0
# 覆蓋儲存
esc:wq
- 重啟資料庫
sh
# 重啟命令
service mysql restart
- 修改資料庫中user的host
- 新增使用者並允許遠端訪問
# 新增使用者並允許遠端訪問只需要在user表中增加一個使用者,將host設定為%即可
# 下例預設將所有許可權分配給新使用者,例如:
grant all privileges on *.* to 'lethew'@'%' identified by 'abcdef';
flush privileges;