1,使用root远程连接。
默认root不允许远程连接。
MariaDB [mysql]> select host from user where user='root';
+-----------------------+
| host |
+-----------------------+
| 127.0.0.1 |
| ::1 |
| localhost |
| localhost.localdomain |
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
修改user表root用户host为‘%’,允许root远程连接。
mysql>update user set host = '%' where user = 'root';
- 1
- 1
注意mysql安全性。
$ mysql_secure_installation
Disallow root login remotely? [Y/n]
- 1
- 2
- 3
- 1
- 2
- 3
2,新建用户,修改权限,用新用户远程连接。
create user ‘username’@’host’ identified by ‘password’;
grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by ‘连接口令’;
直接用grant新建相应权限用户。
MariaDB [(none)]> grant all on testdb.* to test identified by 'test';
- 1
- 1
先新建用户,然后修改权限。
MariaDB [mysql]> create user u1 identified by 'u1';
MariaDB [mysql]> grant insert,update,delete on testdb.* to u1 ;
- 1
- 2
- 1
- 2
使用密码的hash值。
MariaDB [(none)]> select password('hash');
+-------------------------------------------+
| password('hash') |
+-------------------------------------------+
| *06744BAD282D871C1839AF2DF4E6977CD473867F |
+-------------------------------------------+
时间: 2024-11-09 03:04:45