码迷,mamicode.com
首页 > 数据库 > 详细

mysql/MariaDB 搭建后创建密码及开启远程

时间:2018-05-31 12:52:02      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:访问   where   root密码   mysql   用户名   dmi   span   select   mysq   

创建密码:

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 root@% 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 搭建后创建密码及开启远程

标签:访问   where   root密码   mysql   用户名   dmi   span   select   mysq   

原文地址:https://www.cnblogs.com/kaneyang/p/9116057.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!