Ubuntu 18.04 安装 mysql 并且设置远程可登陆连接
Ubuntu18.04 安裝MySQL
環(huán)境信息:?
OS:Ubuntu18.04?
MySQL: 5.7.25-0ubuntu0.18.04.2
?
1.安裝MySQL
在 Ubuntu 18.04 中,默認情況下,只有最新版本的 MySQL 包含在 APT 軟件包存儲庫中,要安裝它,只需更新服務器上的包索引并安裝默認包 apt-get。
?
?
2 .配置MySQL
2.1 安裝配置
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) : Y (我的選項)#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 (我的選項)2.2 檢查mysql服務狀態(tài):
systemctl status mysql.service顯示如下結果說明mysql服務是正常的:
3.配置遠程訪問
在Ubuntu下MySQL缺省是只允許本地訪問的,使用workbench連接工具是連不上的;?
如果你要其他機器也能夠訪問的話,那么需要改變/etc/mysql/my.cnf配置文件;?
3.1 首先用根用戶進入:
sudo mysql -uroot -p默認的MySQL安裝之后根用戶是沒有密碼的,命令執(zhí)行后會讓你設置root的密碼,進入root后才能進行其他設置
以root進入mysql后也可用命令給root設置密碼:
GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123";3.2 新建數據庫和用戶?
用root用戶新建數據和用作遠程訪問的用戶
3.3 進行遠程訪問或控制配置
##1 允許chen用戶可以從任意機器上登入mysql GRANT ALL PRIVILEGES ON weixx.* TO chen@"%" IDENTIFIED BY "123"; $sudo vim /etc/mysql/my.cnf##在頭部添加如下配置,[mysqld] $sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf## 將 bind-address 改成如下所示:以支持在其他機器上連接數據庫bind-address = 0.0.0.03.4 配置好了之后,就需要從起 mysql?
$ service mysql restart?
4.使用workbench連接數據庫
安裝?workbench?
輸入命令:
sudo apt-get install mysql-workbench安裝完成后,搜索workbench,并打開它
打開workbench進行連接配置:?
上述是在本機上連接的。
下面從其他機器連接:
?
附:Navicat12 for mysql?的激活教程? ??https://blog.csdn.net/u013600314/article/details/80605981
基于阿里云Ubuntu安裝和配置PostgreSQL遠程連接:?https://blog.csdn.net/LTAO427/article/details/108418389
總結
以上是生活随笔為你收集整理的Ubuntu 18.04 安装 mysql 并且设置远程可登陆连接的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 拒载制度失灵?台湾一空服员被逼帮旅客“擦
- 下一篇: web.csproj Compile