# 阿里云mariadb/mysql修改root密码，开启远程连接


mariadb 修改root密码

```
# mysql -uroot -p /*输入密码进入*/  
/*第一个方式：直接编辑数据库字段*/  
MariaDB [(none)]> use mysql;  
MariaDB [mysql]> UPDATE user SET password=password('newpassword') WHERE user='root';  
MariaDB [mysql]> flush privileges;  
MariaDB [mysql]> exit  
/*第二个方式：修改密码，不用进入mysql*/  
MariaDB [(none)]> SET password for 'root'@'localhost'=password('newpassword');  
MariaDB [(none)]> exit;  
```

开启远程链接，先进入`mysql` 库

```
MariaDB [(none)]> use mysql
Database changed
```

然后：

```
MariaDB [mysql]> update user set host='%' where user='root' and host='localhost';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
```

这个是吧远程开了，但是本地连接被禁止了。 

单独开启一个远程连接，不影响本地的话，用

```
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
```

刷新权限：

```
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
```


