日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

Ubuntu 18.04 安装 mysql 并且设置远程可登陆连接

發(fā)布時間:2025/3/15 数据库 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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。

#命令1 sudo apt-get update #命令2 sudo apt-get install mysql-server

?

?

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用戶新建數據和用作遠程訪問的用戶

##1 創(chuàng)建數據庫weixx CREATE DATABASE weixx; ##2 創(chuàng)建用戶chen(密碼123) 并賦予其weixx數據庫的所有權限 GRANT ALL PRIVILEGES ON weixx.* TO chen@localhost IDENTIFIED BY "123";

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.0

3.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 并且设置远程可登陆连接的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。