移除mysql(包括mysql-apt-config,server和client)
sudo apt-get purge mysql-server mysql-client mysql-common
sudo apt-get purge mysql-apt-config
sudo apt-get autoremove
sudo apt-get autoclean
刪除mysql相關包
dpkg --list|grep mysql
sudo dpkg -P mysql-community-client
sudo dpkg -P mysql-community-server
sudo dpkg -P mysql-apt-config
重裝軟件包如: ubuntu-desktop
sudo apt-get install --reinstall ubuntu-desktop
安裝依賴關係
sudo apt-get install libaio1
下載軟件mysql-apt-config<version>.deb
下載地址:
http://dev.mysql.com/downloads/repo/apt/.
wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb
安裝到你的系統中
sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb
出現如下界面,選擇 Ubuntu Bionic
回車後出現以下的選項 選擇第一項Mysql8.0 回車,可以在裏面進行更換
選擇 mysql5.7 回車點擊OK
更新倉庫
sudo apt-get update
sudo apt-cache policy mysql-server
這裏命令會輸出,已經有了5.7.X
mysql-server:
已安裝:(無)
候選: 8.0.27-0ubuntu0.20.04.1
版本列表:
8.0.27-0ubuntu0.20.04.1 500
500 http://cn.archive.ubuntu.com/ubuntu focal-updates/main amd64 Packages
500 http://cn.archive.ubuntu.com/ubuntu focal-updates/main i386 Packages
500 http://cn.archive.ubuntu.com/ubuntu focal-security/main amd64 Packages
500 http://cn.archive.ubuntu.com/ubuntu focal-security/main i386 Packages
8.0.19-0ubuntu5 500
500 http://cn.archive.ubuntu.com/ubuntu focal/main amd64 Packages
500 http://cn.archive.ubuntu.com/ubuntu focal/main i386 Packages
5.7.36-1ubuntu18.04 500
500 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 Packages
安裝MySQL服務器
sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*
之後一直輸入Y進行安裝,併爲root創建密碼
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關係樹
正在讀取狀態信息... 完成
爲 mysql-client 選定了版本 5.7.36-1ubuntu18.04 (MySQL:repo.mysql.com [amd64])
爲 mysql-community-server 選定了版本 5.7.36-1ubuntu18.04 (MySQL:repo.mysql.com [amd64])
爲 mysql-server 選定了版本 5.7.36-1ubuntu18.04 (MySQL:repo.mysql.com [amd64])
將會同時安裝下列軟件:
libtinfo5 mysql-common mysql-community-client
下列【新】軟件包將被安裝:
libtinfo5 mysql-client mysql-common mysql-community-client mysql-community-server mysql-server
升級了 0 個軟件包,新安裝了 6 個軟件包,要卸載 0 個軟件包,有 252 個軟件包未被升級。
需要下載 51.3 MB/51.4 MB 的歸檔。
解壓縮後會消耗 313 MB 的額外空間。
您希望繼續執行嗎? [Y/n] Y
獲取:1 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-client amd64 5.7.36-1ubuntu18.04 [14.6 MB]
獲取:1 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-client amd64 5.7.36-1ubuntu18.04 [14.6 MB]
獲取:2 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-client amd64 5.7.36-1ubuntu18.04 [70.3 kB]
獲取:3 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-community-server amd64 5.7.36-1ubuntu18.04 [36.5 MB]
獲取:4 http://repo.mysql.com/apt/ubuntu bionic/mysql-5.7 amd64 mysql-server amd64 5.7.36-1ubuntu18.04 [70.3 kB]
已下載 51.2 MB,耗時 2分 45秒 (310 kB/s)
正在預設定軟件包 ...
正在選中未選擇的軟件包 mysql-common。
(正在讀取數據庫 ... 系統當前共安裝有 270146 個文件和目錄。)
準備解壓 .../0-mysql-common_5.8+1.0.5ubuntu2_all.deb ...
正在解壓 mysql-common (5.8+1.0.5ubuntu2) ...
正在選中未選擇的軟件包 libtinfo5:amd64。
準備解壓 .../1-libtinfo5_6.2-0ubuntu2_amd64.deb ...
正在解壓 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在選中未選擇的軟件包 mysql-community-client。
準備解壓 .../2-mysql-community-client_5.7.36-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-community-client (5.7.36-1ubuntu18.04) ...
正在選中未選擇的軟件包 mysql-client。
準備解壓 .../3-mysql-client_5.7.36-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-client (5.7.36-1ubuntu18.04) ...
正在選中未選擇的軟件包 mysql-community-server。
準備解壓 .../4-mysql-community-server_5.7.36-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-community-server (5.7.36-1ubuntu18.04) ...
正在選中未選擇的軟件包 mysql-server。
準備解壓 .../5-mysql-server_5.7.36-1ubuntu18.04_amd64.deb ...
正在解壓 mysql-server (5.7.36-1ubuntu18.04) ...
正在設置 mysql-common (5.8+1.0.5ubuntu2) ...
update-alternatives: 使用 /etc/mysql/my.cnf.fallback 來在自動模式中提供 /etc/mysql/my.cnf (my.cnf)
正在設置 libtinfo5:amd64 (6.2-0ubuntu2) ...
正在設置 mysql-community-client (5.7.36-1ubuntu18.04) ...
正在設置 mysql-client (5.7.36-1ubuntu18.04) ...
正在設置 mysql-community-server (5.7.36-1ubuntu18.04) ...
update-alternatives: 使用 /etc/mysql/mysql.cnf 來在自動模式中提供 /etc/mysql/my.cnf (my.cnf)
Created symlink /etc/systemd/system/multi-user.target.wants/mysql.service → /lib/systemd/system/mysql.s
ervice.
正在設置 mysql-server (5.7.36-1ubuntu18.04) ...
正在處理用於 systemd (245.4-4ubuntu3.11) 的觸發器 ...
正在處理用於 man-db (2.9.1-1) 的觸發器 ...
正在處理用於 libc-bin (2.31-0ubuntu9.1) 的觸發器 ...
sudo mysql_secure_installation
交互
Securing the MySQL server deployment.
Enter password for user root:
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No: N
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) : N
... skipping.
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. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
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
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : N
... skipping.
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
Success.
All done!
開放遠程連接
vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到 bind-address = 127.0.0.1這一行,改爲 bind-address = 0.0.0.0
進入mysql
create schema test default character set utf8 collate utf8_general_ci;
grant all privileges on test.* to 'test'@'%' identified by 'test' with grant option;
flush privileges;
show grants for test@'%';
重啓mysql
service mysql restart
參考文檔:https://computingforgeeks.com/how-to-install-mysql-on-ubuntu-focal/
6、MySQL 連接
用戶test 密碼 test