Ubuntu18.04安裝MySQL

一、安裝MySQL

sudo apt-get install mysql-server 
sudo apt-get install mysql-client 
sudo apt-get install libmysqlclient-dev

二、更改默認密碼

  • 查看默認配置文件,結果以下圖
sudo cat /etc/mysql/debian.cnf

image.png

圖有‘user=debian-sys-maint’,即爲自動配置的默認用戶;‘password=ol9uVJAxu9L1AzOa’,即爲自動配置的密碼。
  • 以默認配置登錄mysql
mysql -u debian-sys-maint -p        // 用戶名以本身的配置文件爲準
提示輸入密碼,這裏要輸入的就是上一步的‘password=ol9uVJAxu9L1AzOa’(密碼以本身的配置文件爲準)。
  • 更改密碼
use mysql; 
// 下一行,密碼改成了yourpassword,能夠設置成其餘的 
update mysql.user set authentication_string=password('yourpassword') where user='root' and Host ='localhost'; 
update user set plugin="mysql_native_password"; 
flush privileges; 
quit;
  • 重啓MySQL服務
sudo service mysql restart mysql -u root -p 新密碼

image.png

三、配置遠程訪問

  • 編輯配置文件,註釋掉bind-address = 127.0.0.1:
sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
  • 進入mysql服務,執行受權命令
grant all on *.* to root@'%' identified by '你的密碼' with grant option; flush privileges;

四、重啓服務

sudo service mysql restart
如今可在Navicat軟件上遠程鏈接MySQL數據庫。
相關文章
相關標籤/搜索