MySQL数据库刚刚建立的时候,数据库进行远程访问时可能会受限,本节主要告诉你如何对mysql进行远程访问授权
一家日式料理居酒屋墙壁的涂鸦漫画
通过xshell等终端工具登录进centos或linux服务器
[root@localhost ~]# mysql -uroot -p -P3306
输入密码后,即可进入mysql终端模式:
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 29
Server version: 5.5.62-log Source distribution
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| testdb |
| performance_schema |
+--------------------+
给root用户授予远程访问权限
mysql> use mysql;
Database changed
mysql> grant all privileges on *.* to root@'%' identified by "password";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
当然也可以创建用户并授予远程访问的权限
要为用户授予远程访问权限的授予,请在linux机器上登录本机进行操作,若远程通过Navicat等终端操作,会报[Err] 1044 - Access denied for user 'root'@'%' to database 'testdb'
的错误. 操作步骤如下:
mysql> create user 'testuser'@'%' identified by 'passwordtest';
mysql> grant all privileges on testdb.* to "testuser"@'%';
mysql> flush privileges;
或
mysql> grant all privileges on testdb.* to testuser@'%' identified by "passwordtest";
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Comments | NOTHING