Ubuntu18.04 安裝MySQL5.7




一、安裝MySQL

Ubuntu中,默認情況下,只有最新版本的MySQL包含在APT軟件包存儲庫中,要安裝它,只需更新服務器上的包索引並安裝默認包apt-get

sudo apt-get update

1、安裝mysql服務:

sudo apt install mysql-server-5.7

image

2、檢查狀態:

需要先安裝net-tools

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

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

mysql -V

image

4、查看MySQL5.7默認賬號和密碼:

sudo cat /etc/mysql/debian.cnf

image

二、配置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: (重復輸入)

#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服務狀態

systemctl status mysql.service

顯示如下結果說明mysql服務是正常的:

image

四、修改root賬戶秘密認證方式:

連接到Mysql:

sudo mysql -uroot -p

1、查看用戶:

mysql> select user, plugin from mysql.user;

image

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服務

mysql -uroot -p

3、執行授權命令:

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'為你給新增權限用戶設置的密碼。

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.清理殘留數據

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

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

可以到官網,選擇系統點擊跳轉下載 Workbench。

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

sudo apt update
sudo apt install mysql-workbench

啟動 MySQL Workbench。

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

當您第一次啟動 MySQL Workbench 時,應出現如下窗口:

image

連接配置界面

要添加新連接,請單擊 “MySQL Connections” 旁邊帶圓圈的加號⊕。

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

  • 在 “SSH Hostname”中,輸入服務器的主機名或 IP 地址,然后輸入 SSH 端口。
  • 輸入您的遠程 “SSH Username”。對於身份驗證,您可以使用用戶密碼或 SSH 密鑰。
  • 保留 “MySQL Hostname”字段的默認值 (127.0.0.1) 。
  • 在“Username”和“Password”字段中輸入遠程數據庫登錄憑據。

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

image

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

image

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

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM