mysql/MariaDB 搭建后创建密码及开启远程
Posted Nage
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql/MariaDB 搭建后创建密码及开启远程相关的知识,希望对你有一定的参考价值。
创建密码:
mysqladmin -u root -p password newpassword
或
MariaDB [(none)]> use mysql MariaDB [mysql]> update user set password=password("123456")where user=‘root‘; Query OK, 0 rows affected (0.00 sec) Rows matched: 4 Changed: 0 Warnings: 0 MariaDB [mysql]> flush privileges; Query OK, 0 rows affected (0.00 sec)
开启远程服务:
查看user表:可以发现表中没有开启远程的服务 % root
mysql> use mysql; Database changed mysql> select host,user,password from user; +--------------+------+-------------------------------------------+ | host | user | password | +--------------+------+-------------------------------------------+ | localhost | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | | 127.0.0.1 | root | *A731AEBFB621E354CD41BAF207D884A609E81F5E | +--------------+------+-------------------------------------------+ 2 rows in set (0.00 sec)
实现远程连接(授权法):
将host字段的值改为%就表示在任何客户端机器上能以root用户登录到mysql服务器,建议在开发时设为%。
update user set host = ’%’ where user = ’root’; 将权限改为ALL PRIVILEGES
mysql> use mysql; Database changed mysql> grant all privileges on *.* to [email protected]‘%‘ identified by "password"; Query OK, 0 rows affected (0.00 sec)
MariaDB [mysql]> flush privileges;
Query OK, 0 rows affected (0.00 sec) mysql> select host,user,password from user;
+-----------+------+-------------------------------------------+
| host | user | password |
+-----------+------+-------------------------------------------+
| localhost | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| 127.0.0.1 | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| ::1 | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
| localhost | | |
| % | root | *23AE809DDACAF96AF0FD78ED04B6A265E05AA257 |
+-----------+------+-------------------------------------------+
5 rows in set (0.00 sec)
这样机器就可以以用户名root密码远程访问该机器上的MySql.
以上是关于mysql/MariaDB 搭建后创建密码及开启远程的主要内容,如果未能解决你的问题,请参考以下文章
Ubuntu的MySQL(MariaDB)默认密码和修改方法