環境和工具:
宿主機:Window10.
虛擬機:VMware,Ubuntu18.04
數據庫:Server version: 8.0.15 MySQL Community Server
連接工具:SQLyog(僅僅是個工具使用Navicat也可以)
業務需求:
虛擬機的內存不足,打開連接工具卡頓,Ubuntu安裝工具也不方便,做一下記錄。
1、註釋:
使用命令:$ sudo vi /etc/mysql/mysql.conf.d/mysqld.cnf
打開數據庫的配置文件,單行註釋掉bind-address = 127.0.0.1
,有的配置文件是沒有這一行的,安裝的時候選擇默認的是可以遠程訪問。
2、重啓一下服務
重啓數據庫服務生效 sudo service mysql restart
3、登錄修改用戶和權限
首先登錄:
$ mysql -u root -p
Enter password:
然後切換到mysql數據庫(裏面記錄的是用戶的信息和權限):
mysql> 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
接着可以查看root賬戶的登錄權限:
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | toohoo |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | root |
| localhost | toohoo |
+-----------+------------------+
修改登錄權限:
mysql> update user set host = '%' where user = 'root';
Query OK, 1 row affected (0.57 sec)
Rows matched: 1 Changed: 1 Warnings: 0
最後,刷新數據庫生效:
mysql> flush privileges;
Query OK, 0 rows affected (0.26 sec)
再次查看數據庫的時候發現更改成功:
mysql> select host, user from user;
+-----------+------------------+
| host | user |
+-----------+------------------+
| % | root |
| % | toohoo |
| localhost | mysql.infoschema |
| localhost | mysql.session |
| localhost | mysql.sys |
| localhost | toohoo |
+-----------+------------------+
6 rows in set (0.00 sec)
最後使用SQLyog連接即可,將默認的localhost更改爲虛擬機的IP地址即可,輸入3306端口和root用戶以及密碼,點擊連接,成功。