Mariadb遠(yuǎn)程登陸配置及問題解決
前言:
安裝過程不再贅述,直接說問題,mysql的遠(yuǎn)程連接需要解決兩個問題:1.允許root用戶遠(yuǎn)程連接。2.允許任意ip遠(yuǎn)程連接數(shù)據(jù)庫。當(dāng)然,在測試和解決問題之前,得首先保證你的數(shù)據(jù)庫與遠(yuǎn)程主機(jī)之間的網(wǎng)絡(luò)通信沒有問題,簡單的來說,就是互相ping通,其次,為了避免防火墻的干擾,將本地主機(jī)和數(shù)據(jù)庫主機(jī)的防火墻都關(guān)閉,當(dāng)然,生產(chǎn)環(huán)境下防火墻肯定是要打開的,并且需要額外的安全配置。
問題解決:
1.新安裝的數(shù)據(jù)庫默認(rèn)是需要初始化的,在數(shù)據(jù)庫服務(wù)啟動的情況下,使用下面的命令來進(jìn)行初始化。
[root@localhost ~]# mysql_secure_installation New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ... Success! 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? [Y/n] n #如果是為root用戶配置遠(yuǎn)程登陸,這里需要選擇n,不選擇禁止root用戶遠(yuǎn)程登陸,別的選擇都無關(guān)緊要。 ... skipping. By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB![root@localhost ~]# systemctl restart mariadb #完成初始化之后,重啟服務(wù)。
2.允許root用戶遠(yuǎn)程連接與允許任意ip遠(yuǎn)程連接數(shù)據(jù)庫都是可以通過在數(shù)據(jù)庫里執(zhí)行一條命令來實(shí)現(xiàn)的。
這里分為兩種情況:
1)新建admin用戶遠(yuǎn)程連接mysql數(shù)據(jù)庫(新建任意用戶,以admin為例)
grant all on *.* to admin@'%' identified by '123456' with grant option;
flush privileges;
允許任何ip地址(%表示允許任何ip地址)的電腦用admin帳戶和密碼(123456)來訪問這個mysql server。
注意admin賬戶不一定要存在。
2)支持root用戶允許遠(yuǎn)程連接mysql數(shù)據(jù)庫
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
需要注意的是,為root用戶配置遠(yuǎn)程登陸,密碼需要和之前配置的密碼一致。
3.ubuntu系統(tǒng)的額外配置。
Ubuntu系統(tǒng)的my.cnf文件在vim /etc/mysql/mysql.conf.d/mysqld.cnf中,注釋掉其中的
bind-address = 127.0.0.1
centos系統(tǒng)的配置文件中默認(rèn)沒有該行。
檢查的辦法也很簡單,在數(shù)據(jù)庫啟動的前提下,使用netstat -an | grep 3306查看端口的連接信息。0.0.0.0則表示允許任意IP連接。
如圖所示則為允許任意IP連接。
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
超詳細(xì)mysql left join,right join,inner join用法分析
比較詳細(xì)的mysql的幾種連接功能分析,只要你看完就能學(xué)會的好東西2008-08-08Navicat連接服務(wù)器MySQL數(shù)據(jù)庫步驟及遇到錯誤和問題
Navicat是一款強(qiáng)大的數(shù)據(jù)庫管理工具,可以用來遠(yuǎn)程連接MySQL服務(wù)器,下面這篇文章主要給大家介紹了關(guān)于Navicat連接服務(wù)器MySQL數(shù)據(jù)庫步驟及遇到錯誤和問題的相關(guān)資料,文中通過代碼及圖文介紹的非常詳細(xì),需要的朋友可以參考下2024-07-07數(shù)據(jù)庫崩潰,利用備份和日志進(jìn)行災(zāi)難恢復(fù)
我相信數(shù)據(jù)庫崩潰都不是大家所愿意看到的,但是這種情況發(fā)生時我們要采取補(bǔ)救措施,本文就是介紹了如何利用備份和日志進(jìn)行災(zāi)難恢復(fù),需要的朋友可以參考下2015-07-07老鳥帶你開發(fā)專業(yè)規(guī)范的MySQL啟動腳本
這篇文章主要介紹了老鳥帶你開發(fā)專業(yè)規(guī)范的MySQL啟動腳本,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09MySQL錯誤“Data?too?long”的原因、解決方案與優(yōu)化策略
MySQL作為重要的數(shù)據(jù)庫系統(tǒng),在數(shù)據(jù)插入時可能遇到“Data?too?long?for?column”錯誤,本文探討了該錯誤的原因、解決方案及預(yù)防措施,如調(diào)整字段長度、使用TEXT類型等,旨在優(yōu)化數(shù)據(jù)庫設(shè)計,提升性能和用戶體驗(yàn),需要的朋友可以參考下2024-09-09ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法
下面小編就為大家分享一篇ubuntu server配置mysql并實(shí)現(xiàn)遠(yuǎn)程連接的操作方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2017-12-12