mysql安裝後開啟遠程

來源:互聯網
上載者:User

標籤:需要   操作   mct   zone   登入   cal   color   string   查看   

作業系統為centos7 64

1、修改 /etc/my.cnf,在 [mysqld] 小節下添加一行:skip-grant-tables=1

這一行配置讓 mysqld 啟動時不對密碼進行驗證

2、重啟 mysqld 服務:systemctl restart mysqld

3、使用 root 使用者登入到 mysql:mysql -u root 

4、切換到mysql資料庫,更新 user 表:

update user set authentication_string = password(‘root‘), password_expired = ‘N‘, password_last_changed = now() where user = ‘root‘;

在之前的版本中,密碼欄位的欄位名是 password,5.7版本改為了 authentication_string

5、退出 mysql,編輯 /etc/my.cnf 檔案,刪除 skip-grant-tables=1 的內容

6、重啟 mysqld 服務,再用新密碼登入即可

 

另外,MySQL 5.7 在初始安裝後(CentOS7 作業系統)會產生隨機初始密碼,並在 /var/log/mysqld.log 中有記錄,可以通過 cat 命令查看,找 password 關鍵字

找到密碼後,在本機以初始密碼登入,並且(也只能)通過 alter user ‘root‘@‘localhost‘ identified by ‘root‘ 命令,修改 root 使用者的密碼為 root,然後退出,重新以root使用者和剛設定的密碼進行登入即可。

 

設定允許遠程登入

Mysql預設不允許遠程登入,我們需要設定下,並且防火牆開放3306連接埠;

 

mysql>CREATE USER ‘tom‘@‘localhost‘ IDENTIFIED BY ‘123.com‘;   //建立使用者

[[email protected] ~]# firewall-cmd --zone=public --add-port=3306/tcp --permanent

success

[[email protected] ~]# firewall-cmd --reload

success

[[email protected] ~]# 

開放3306連接埠

mysql安裝後開啟遠程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.