Ubuntu20.4安装及配置mysql详细教程
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu20.4安装及配置mysql详细教程
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、通過apt 安裝MySQL服務(推薦,會安裝最新版)
#命令1 更新源 sudo apt-get update#命令2 安裝mysql服務 sudo apt-get install mysql-server二、初始化配置
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 (選擇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 (選擇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 (選擇N,允許root遠程連接)#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 (選擇N,不刪除test數據庫)#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 (選擇Y,修改權限立即生效)三、檢查mysql服務狀態
systemctl status mysql.service四、配置遠程訪問
在Ubuntu下MySQL缺省是只允許本地訪問的,使用workbench連接工具是連不上的;
如果你要其他機器也能夠訪問的話,需要進行配置;
找到 bind-address 修改值為 0.0.0.0(如果需要遠程訪問)
登錄數據庫
sudo mysql -uroot -p如果為了安全性,設置了用戶驗證,必須使用sudo,才能登錄,出現如下情況:(盡量不要設置ubuntu用戶在驗證,否則會很麻煩)
mysql -uroot -p
解決方法:
添加以下字段
[mysqld] skip-grant-tables保存后重啟mysql,可以正常登陸了
systemctl restart mysql這樣操作后,是相當于跳過了mysql的密碼認證。很不安全,直接就可以登錄進去。
總結
以上是生活随笔為你收集整理的Ubuntu20.4安装及配置mysql详细教程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【django】如何搭建虚拟环境(解决m
- 下一篇: 【django】配置MySQL数据库【3