Ubuntu 安装MySQL 并设置其他主机可访问
生活随笔
收集整理的這篇文章主要介紹了
Ubuntu 安装MySQL 并设置其他主机可访问
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Ubuntu18.04 安裝MySQL
環境信息:
OS:Ubuntu18.04
MySQL: 5.7.22
1.安裝MySQL
在Ubuntu中,默認情況下,只有最新版本的MySQL包含在APT軟件包存儲庫中,要安裝它,只需更新服務器上的包索引并安裝默認包apt-get。
#命令1 sudo apt-get update #命令2 sudo apt-get install mysql-server2.配置MySQL
2.1 初始化配置
配置項較多,如下所示:
#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服務狀態
systemctl status mysql.service顯示如下結果說明mysql服務是正常的:
3.配置遠程訪問
在Ubuntu下MySQL缺省是只允許本地訪問的,使用workbench連接工具是連不上的;
如果你要其他機器也能夠訪問的話,需要進行配置;
3.1 首先用根用戶進入
sudo mysql -uroot -p登入root進行其他設置:
其中root@localhos,localhost就是本地訪問,配置成%就是所有主機都可連接;
第二個'123456'為你給新增權限用戶設置的密碼,%代表所有主機,也可以是具體的ip;
不過這隨設置了%但我root通過工具還是登陸不進去,可能是為了安全性,所以新建數據庫和用戶;
3.2 新建數據庫和用戶
用root用戶新建數據和用作遠程訪問的用戶
##1 創建數據庫weixx CREATE DATABASE weixx; ##2 創建用戶wxx(密碼654321) 并允許wxx用戶可以從任意機器上登入mysql的weixx數據庫 GRANT ALL PRIVILEGES ON weixx.* TO wxx@"%" IDENTIFIED BY "654321";總結
以上是生活随笔為你收集整理的Ubuntu 安装MySQL 并设置其他主机可访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos 安装安全狗
- 下一篇: ubantu18.10安装mysql