Ubuntu系統(tǒng)安裝與配置MySQL
一、安裝MySQL
在Ubuntu中,默認情況下,只有最新版本的MySQL包含在APT軟件包存儲庫中,要安裝它,只需更新服務(wù)器上的包索引并安裝默認包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默認賬號和密碼:
sudo cat /etc/mysql/debian.cnf

二、配置MySQL
sudo mysql_secure_installation
配置項較多,如下所示:
#1 VALIDATE PASSWORD PLUGIN can be used to test passwords... Press y|Y for Yes, any other key for No: N (我的選項) #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 (我的選項) #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 (我的選項) #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 (我的選項) #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 (我的選項)
三、查mysql服務(wù)狀態(tài)
systemctl status mysql.service
顯示如下結(jié)果說明mysql服務(wù)是正常的:

四、修改root賬戶秘密認證方式:
連接到Mysql:
sudo mysql -uroot -p
1、查看用戶:
mysql> select user, plugin from mysql.user;

2、重置Root密碼,修改認證方式:
mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root';
mysql>flush privileges;
mysql> exit五、配置遠程訪問mysql:
1、修改配置文件,注釋掉bind-address = 127.0.0.1
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
2、保存退出,然后進入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就是本地訪問,配置成%就是所有主機都可連接;第二個'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)點擊跳轉(zhuǎn)下載 Workbench。
也可以更新軟件包索引并直接安裝 MySQL Workbench 軟件包:
sudo apt update sudo apt install mysql-workbench
啟動 MySQL Workbench。
您可以通過鍵入 mysql-workbench 或單擊 MySQL Workbench 圖標 (Activities -> MySQL Workbench) 從命令行啟動它。
當您第一次啟動 MySQL Workbench 時,應(yīng)出現(xiàn)如下窗口:

連接配置界面
要添加新連接,請單擊 “MySQL Connections” 旁邊帶圓圈的加號⊕。
將打開一個新窗口 “Setup New Connection form”。在此示例中,我們將通過 SSH 連接到遠程服務(wù)器。在“Connection name”字段中輸入有意義的名稱,然后 Standard TCP/IP over SSH 從“連接方法”下拉列表中進行選擇。
- 在 “SSH Hostname”中,輸入服務(wù)器的主機名或 IP 地址,然后輸入 SSH 端口。
- 輸入您的遠程 “SSH Username”。對于身份驗證,您可以使用用戶密碼或 SSH 密鑰。
- 保留 “MySQL Hostname”字段的默認值 (127.0.0.1) 。
- 在“Username”和“Password”字段中輸入遠程數(shù)據(jù)庫登錄憑據(jù)。
完成后,單擊“測試連接”按鈕。

這里直接點擊已有的連接:

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

到此這篇關(guān)于Ubuntu系統(tǒng)安裝與配置MySQL的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
MySQL數(shù)據(jù)庫表的合并及分區(qū)方式
這篇文章主要介紹了MySQL數(shù)據(jù)庫表的合并及分區(qū)方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-08-08
mysql source 命令導(dǎo)入大的sql文件的方法
本文將詳細介紹mysql source 命令導(dǎo)入大的sql文件的方法;需要的朋友可以參考下2012-11-11
監(jiān)聽mysql表內(nèi)容變化 mysql開啟binlog
這篇文章主要給大家介紹了關(guān)于監(jiān)聽mysql表內(nèi)容變化,mysql開啟binlog的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家學(xué)習(xí)或者使用mysql具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-08-08

