一、Ubuntu Server 16.04 安裝MySQL
- 使用root賬號(hào)
sudo apt-get install mysql-serverapt-get isntall mysql-clientapt-get install libmysqlclient-dev
如果中途有問題就執(zhí)行以下 apt-get update - 以上3個(gè)軟件包安裝完成后,使用如下命令查詢是否安裝成功:
sudo netstat -tap | grep mysql
查詢結(jié)果如下圖所示,表示安裝成功。
root@ubuntu:~# netstat -tap | grep mysqltcp6 0 0 [::]:mysql [::]:* LISTEN 7510/mysqld root@ubuntu:~#
二、設(shè)置mysql遠(yuǎn)程訪問 - 編輯mysql配置文件,把其中bind-address = 127.0.0.1注釋了
vi /etc/mysql/my.cnf - 使用root進(jìn)入mysql命令行,執(zhí)行如下2個(gè)命令,示例中mysql的root賬號(hào)密碼:root
root@ubuntu:~# mysql -uroot -proot
mysql>grant all on . to root@'%' identified by 'root' with grand option;
.:第一個(gè)代表數(shù)據(jù)庫名;第二個(gè)代表表名。這里的意思是所有數(shù)據(jù)庫里的所有表都授權(quán)給用戶。root:授予root賬號(hào)。“%”:表示授權(quán)的用戶IP可以指定,這里代表任意的IP地址都能訪問MySQL數(shù)據(jù)庫?!皃assword”:分配賬號(hào)對(duì)應(yīng)的密碼,這里密碼自己替換成你的 mysql root帳號(hào) 密碼。
mysql>flush privileges;
刷新權(quán)限信息,也即是讓我們所作的設(shè)置馬上生效。 - 重啟mysql
/etc/init.d/mysql restart
更多Ubuntu相關(guān)信息見Ubuntu 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=2
本文永久更新鏈接地址:http://www.linuxidc.com/Linux/2016-07/133091.htm