(有什么问题欢迎指教,企鹅:2172243813 更多资讯尽在通天源码论坛)
对于我们刚开始安装的mysql获取mariadb来说,默认是不开启远程连接的。所以需要我们手动开启远程连接的权限。
- 登录mysql
mysql -u root -p
Enter password:
如果刚安装没有设置密码的话就直接回车
- 切换到mysql这个数据库
use mysql;
- 修改root的host为%
update user set host = '%' where user ='root';
检查是否以修改:
select host, user from user;
+--------------+------+
| host | user |
+--------------+------+
| % | root |
| 127.0.0.1 | root |
| ::1 | root |
| dfa0e46aa7ac | |
| dfa0e46aa7ac | root |
| localhost | |
+--------------+------+
- 设置root密码
UPDATE user SET Password = PASSWORD('123456') WHERE user ='root';
检查:
select host, user , password fromuser;
+--------------+------+-------------------------------------------+
| host | user | password |
+--------------+------+-------------------------------------------+
| % | root |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| dfa0e46aa7ac | root | *6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9|
| 127.0.0.1 | root |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| ::1 | root |*6BB4837EB74329105EE4568DDA7DC67ED2CA2AD9 |
| localhost | | |
| dfa0e46aa7ac | | |
+--------------+------+-------------------------------------------+
注意sql语句不要写错了,是Password =PASSWORD('123456'),PASSWORD函数会对密码进行加密,匹配时同样会对输入的密码加密然后再比对。
- 刷新修改,使其生效
flush privileges;
- 使用客户端连接检测是否成功
本文来自苦逼IT小子的新浪博客