環境
MySQL 版本 Server version: 5.5.64-MariaDB MariaDB Server
Linux版本 CentOS Linux release 7.6.1810 (AltArch)
操作
1)root默認情況下無須密碼登陸,直接回車,要求輸入密碼,直接回車
root@host-172-16-61-102 bin]# mysql -uroot -p
PASSWORD:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 35
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
2)選擇數據庫,否則執行指令出錯No database selected
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
3)指定root用戶的密碼是root
MariaDB [mysql]> update user set password=password("root")where user='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 5 Changed: 0 Warnings: 0
注意:
執行無效情況下,可能是版本的問題,查看是否是password字段還是authentication_string字段保存密碼
update user set password = password("root"),authentication_string=password("root") where user=root;
通過指令desc user 可以查看當前user的表結構
4)授予訪問權限
root用戶使用密碼從任何主機連接到mysql服務器
MariaDB [mysql]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
其中BY後面是root用戶的密碼:root
只允許192.168.10.168通過root用戶連接到mysql服務器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.10.168' IDENTIFIED BY 'root' WITH GRANT OPTION;
5)刷新權限
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
注意:
1)Navicat遠程登陸失敗
1045 - Access denied for user '[email protected]' (using password: YES)
授予訪問權限沒有執行,執行第四步
可通過指令 select host,user from user;查看是否有遠程訪問的權限
2)關閉防火牆
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啓動
開啓端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
mysql服務啓動,可以通過lsof -i:3306端口是否監聽
重啓防火牆
firewall-cmd --reload