溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Ubuntu系統(tǒng)如何安裝與配置MySQL

發(fā)布時(shí)間:2022-06-01 13:45:42 來源:億速云 閱讀:3964 作者:iii 欄目:開發(fā)技術(shù)

這篇“Ubuntu系統(tǒng)如何安裝與配置MySQL”文章的知識(shí)點(diǎn)大部分人都不太理解,所以小編給大家總結(jié)了以下內(nèi)容,內(nèi)容詳細(xì),步驟清晰,具有一定的借鑒價(jià)值,希望大家閱讀完這篇文章能有所收獲,下面我們一起來看看這篇“Ubuntu系統(tǒng)如何安裝與配置MySQL”文章吧。

一、安裝MySQL

Ubuntu中,默認(rèn)情況下,只有最新版本的MySQL包含在APT軟件包存儲(chǔ)庫中,要安裝它,只需更新服務(wù)器上的包索引并安裝默認(rèn)包apt-get。

sudo apt-get update

1、安裝mysql服務(wù):

sudo apt install mysql-server-5.7

Ubuntu系統(tǒng)如何安裝與配置MySQL

2、檢查狀態(tài):

需要先安裝net-tools

sudo apt install net-tools
sudo netstat -tap | grep mysql

3、注意查看mysql版本使用:

mysql -V

Ubuntu系統(tǒng)如何安裝與配置MySQL

4、查看MySQL5.7默認(rèn)賬號(hào)和密碼:

sudo cat /etc/mysql/debian.cnf

Ubuntu系統(tǒng)如何安裝與配置MySQL

二、配置MySQL

sudo mysql_secure_installation

配置項(xiàng)較多,如下所示:

#1
VALIDATE PASSWORD PLUGIN can be used to test passwords...
Press y|Y for Yes, any other key for No: N (我的選項(xiàng))

#2
 Please set the password for root here...
 New password: (輸入密碼)
Re-enter new password: (重復(fù)輸入)

#3
 By default, a MySQL installation has an anonymous user,
 allowing anyone to log into MySQL without having to have
 a user account created for them...
 Remove anonymous users? (Press y|Y for Yes, any other key for No) : N (我的選項(xiàng))

#4
 Normally, root should only be allowed to connect from
 'localhost'. This ensures that someone cannot guess at
 the root password from the network...
 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : N (我的選項(xiàng))

#5
 By default, MySQL comes with a database named 'test' that
 anyone can access...
 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N (我的選項(xiàng))

#6
 Reloading the privilege tables will ensure that all changes
 made so far will take effect immediately.
 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y (我的選項(xiàng))

三、查mysql服務(wù)狀態(tài)

systemctl status mysql.service

顯示如下結(jié)果說明mysql服務(wù)是正常的:

Ubuntu系統(tǒng)如何安裝與配置MySQL

四、修改root賬戶秘密認(rèn)證方式:

連接到Mysql:

sudo mysql -uroot -p

1、查看用戶:

mysql> select user, plugin from mysql.user;

Ubuntu系統(tǒng)如何安裝與配置MySQL

2、重置Root密碼,修改認(rèn)證方式:

mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql>flush privileges;
mysql> exit

五、配置遠(yuǎn)程訪問mysql:

1、修改配置文件,注釋掉bind-address = 127.0.0.1

sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf

2、保存退出,然后進(jìn)入mysql服務(wù)

mysql -uroot -p

3、執(zhí)行授權(quán)命令:

mysql>grant all ON *.* to root@'%' identified by '123456' with grant option;
 Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
 Query OK, 0 rows affected (0.00 sec)
mysql> exit
 Bye

其中root@%,localhost就是本地訪問,配置成%就是所有主機(jī)都可連接;第二個(gè)'123456'為你給新增權(quán)限用戶設(shè)置的密碼。

4、重啟

sudo /etc/init.d/mysql restart

六、刪除MySQL

想安裝MySQL 8.0或者重裝MySQL 5.7的前提條件,可以先刪除已有的。

1.刪除 mysql:

sudo apt autoremove --purge mysql-server-*
sudo apt remove mysql-server
sudo apt autoremove mysql-server
sudo apt remove mysql-common

2.清理殘留數(shù)據(jù)

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

七、安裝mysql可視化工具mysql-workbench

可以到官網(wǎng),選擇系統(tǒng)點(diǎn)擊跳轉(zhuǎn)下載 Workbench。

也可以更新軟件包索引并直接安裝 MySQL Workbench 軟件包:

sudo apt update
sudo apt install mysql-workbench

啟動(dòng) MySQL Workbench。

您可以通過鍵入 mysql-workbench 或單擊 MySQL Workbench 圖標(biāo) (Activities -> MySQL Workbench) 從命令行啟動(dòng)它。

當(dāng)您第一次啟動(dòng) MySQL Workbench 時(shí),應(yīng)出現(xiàn)如下窗口:

Ubuntu系統(tǒng)如何安裝與配置MySQL

連接配置界面

要添加新連接,請(qǐng)單擊 “MySQL Connections” 旁邊帶圓圈的加號(hào)⊕。

將打開一個(gè)新窗口 “Setup New Connection form”。在此示例中,我們將通過 SSH 連接到遠(yuǎn)程服務(wù)器。在“Connection name”字段中輸入有意義的名稱,然后 Standard TCP/IP over SSH 從“連接方法”下拉列表中進(jìn)行選擇。

  • 在 “SSH Hostname”中,輸入服務(wù)器的主機(jī)名或 IP 地址,然后輸入 SSH 端口。

  • 輸入您的遠(yuǎn)程 “SSH Username”。對(duì)于身份驗(yàn)證,您可以使用用戶密碼或 SSH 密鑰。

  • 保留 “MySQL Hostname”字段的默認(rèn)值 (127.0.0.1) 。

  • 在“Username”和“Password”字段中輸入遠(yuǎn)程數(shù)據(jù)庫登錄憑據(jù)。

完成后,單擊“測試連接”按鈕。

Ubuntu系統(tǒng)如何安裝與配置MySQL

這里直接點(diǎn)擊已有的連接:

Ubuntu系統(tǒng)如何安裝與配置MySQL

配置完成后,在主界面選擇數(shù)據(jù)庫進(jìn)行連接:

Ubuntu系統(tǒng)如何安裝與配置MySQL

以上就是關(guān)于“Ubuntu系統(tǒng)如何安裝與配置MySQL”這篇文章的內(nèi)容,相信大家都有了一定的了解,希望小編分享的內(nèi)容對(duì)大家有幫助,若想了解更多相關(guān)的知識(shí)內(nèi)容,請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI