Mariadb遠程登陸配置及問題解決
前言:
安裝過程不再贅述,直接說問題,mysql的遠程連接需要解決兩個問題:1.允許root用戶遠程連接。2.允許任意ip遠程連接數(shù)據(jù)庫。當然,在測試和解決問題之前,得首先保證你的數(shù)據(jù)庫與遠程主機之間的網(wǎng)絡(luò)通信沒有問題,簡單的來說,就是互相ping通,其次,為了避免防火墻的干擾,將本地主機和數(shù)據(jù)庫主機的防火墻都關(guān)閉,當然,生產(chǎn)環(huán)境下防火墻肯定是要打開的,并且需要額外的安全配置。
問題解決:
1.新安裝的數(shù)據(jù)庫默認是需要初始化的,在數(shù)據(jù)庫服務(wù)啟動的情況下,使用下面的命令來進行初始化。
[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用戶配置遠程登陸,這里需要選擇n,不選擇禁止root用戶遠程登陸,別的選擇都無關(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用戶遠程連接與允許任意ip遠程連接數(shù)據(jù)庫都是可以通過在數(shù)據(jù)庫里執(zhí)行一條命令來實現(xiàn)的。
這里分為兩種情況:
1)新建admin用戶遠程連接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用戶允許遠程連接mysql數(shù)據(jù)庫
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
flush privileges;
需要注意的是,為root用戶配置遠程登陸,密碼需要和之前配置的密碼一致。
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)的配置文件中默認沒有該行。
檢查的辦法也很簡單,在數(shù)據(jù)庫啟動的前提下,使用netstat -an | grep 3306查看端口的連接信息。0.0.0.0則表示允許任意IP連接。

如圖所示則為允許任意IP連接。
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Mysql啟動中 InnoDB: Error: log file ./ib_logfile0 is of differe
對于使用了默認 my.cnf(一般教程都會教你使用support-files/my-medium.cnf)的Mysql服務(wù)來說如果中間使用了innodb的話,innodb默認的log file大小是56M2011-05-05
連接mysql報錯——沒有設(shè)置“usessl=false”的問題
這篇文章主要介紹了連接mysql報錯——沒有設(shè)置“usessl=false”的問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08
Mac os 解決無法使用localhost連接mysql問題
今天在mac上搭建好了php的環(huán)境,把先前在window、linux下運行良好的程序放在mac上,居然出現(xiàn)訪問不了數(shù)據(jù)庫,數(shù)據(jù)庫連接的host用的是localhost,可以確認數(shù)據(jù)庫配置是正確的,下面特為大家分享下2014-05-05
SQL實戰(zhàn)演練之網(wǎng)上商城數(shù)據(jù)庫商品類別數(shù)據(jù)操作
一直認為,扎實的SQL功底是一名數(shù)據(jù)分析師的安身立命之本,甚至可以稱得上是所有數(shù)據(jù)從業(yè)者的基本功。當然,這里的SQL絕不單單是寫幾條查詢語句那么簡單,接下來請跟著小編通過案例項目演練一遍商品類別的數(shù)據(jù)操作吧2021-10-10
記一次mysql5.7測試數(shù)據(jù)庫被刪表的問題
這篇文章主要介紹了記一次mysql5.7測試數(shù)據(jù)庫被刪表的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-11-11

