在Ubuntu
中,默認狀況下,只有最新版本的MySQL
包含在APT
軟件包存儲庫中,要安裝它,只需更新服務器上的包索引並安裝默認包apt-get
。mysql
sudo apt-get update
一、安裝mysql服務:linux
sudo apt install mysql-server-5.7
二、檢查狀態:sql
須要先安裝net-tools
數據庫
sudo apt install net-tools
sudo netstat -tap | grep mysql
三、注意查看mysql版本使用:服務器
mysql -V
四、查看MySQL5.7默認帳號和密碼:ide
sudo cat /etc/mysql/debian.cnf
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 (個人選項)
systemctl status mysql.service
顯示以下結果說明mysql服務是正常的:測試
鏈接到Mysql:idea
sudo mysql -uroot -p
一、查看用戶:spa
mysql> select user, plugin from mysql.user;
二、重置Root密碼,修改認證方式:
mysql> update mysql.user set authentication_string=PASSWORD('123456'), plugin='mysql_native_password' where user='root'; mysql>flush privileges; mysql> exit
一、修改配置文件,註釋掉bind-address = 127.0.0.1
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
二、保存退出,而後進入mysql服務
mysql -uroot -p
三、執行受權命令:
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'
爲你給新增權限用戶設置的密碼。
四、重啓
sudo /etc/init.d/mysql restart
想安裝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 Workbench 軟件包:
sudo apt update
sudo apt install mysql-workbench
啓動 MySQL Workbench。
您能夠經過鍵入 mysql-workbench
或單擊 MySQL Workbench 圖標 (Activities -> MySQL Workbench
) 從命令行啓動它。
當您第一次啓動 MySQL Workbench 時,應出現以下窗口:
鏈接配置界面
要添加新鏈接,請單擊 「MySQL Connections」 旁邊帶圓圈的加號⊕。
將打開一個新窗口 「Setup New Connection form」。在此示例中,咱們將經過 SSH 鏈接到遠程服務器。在「Connection name」字段中輸入有意義的名稱,而後 Standard TCP/IP over SSH
從「鏈接方法」下拉列表中進行選擇。
完成後,單擊「測試鏈接」按鈕。
這裏直接點擊已有的鏈接:
配置完成後,在主界面選擇數據庫進行鏈接: