Ubuntu系統(tǒng)安裝與配置MySQL
一、安裝MySQL
在Ubuntu
中,默認(rèn)情況下,只有最新版本的MySQL
包含在APT
軟件包存儲(chǔ)庫(kù)中,要安裝它,只需更新服務(wù)器上的包索引并安裝默認(rèn)包apt-get
。
sudo apt-get update
1、安裝mysql服務(wù):
sudo apt install mysql-server-5.7
2、檢查狀態(tài):
需要先安裝net-tools
sudo apt install net-tools sudo netstat -tap | grep mysql
3、注意查看mysql版本使用:
mysql -V
4、查看MySQL5.7默認(rèn)賬號(hào)和密碼:
sudo cat /etc/mysql/debian.cnf
二、配置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ù)是正常的:
四、修改root賬戶秘密認(rèn)證方式:
連接到Mysql:
sudo mysql -uroot -p
1、查看用戶:
mysql> select user, plugin from mysql.user;
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)如下窗口:
連接配置界面
要添加新連接,請(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ù)庫(kù)登錄憑據(jù)。
完成后,單擊“測(cè)試連接”按鈕。
這里直接點(diǎn)擊已有的連接:
配置完成后,在主界面選擇數(shù)據(jù)庫(kù)進(jìn)行連接:
到此這篇關(guān)于Ubuntu系統(tǒng)安裝與配置MySQL的文章就介紹到這了。希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Mysql主從三種復(fù)制模式(異步復(fù)制,半同步復(fù)制,組復(fù)制)
這篇文章主要介紹了Mysql主從三種復(fù)制模式(異步復(fù)制,半同步復(fù)制,組復(fù)制),MySQL異步復(fù)制是主從復(fù)制過程中默認(rèn)的復(fù)制模式,下文簡(jiǎn)單介紹,感興趣的朋友可以參考一下2022-08-08