美文网首页
Ubuntu1804安装并配置MySQL的远程登录

Ubuntu1804安装并配置MySQL的远程登录

作者: Jesse4023 | 来源:发表于2019-05-25 22:20 被阅读0次

    安装:

    apt-get install mysql-server

    设置root密码:

    nano /etc/mysql/debian.cnf                        #找到password一行,复制密码

    mysql -u debian-sys-maint -p 刚刚复制的密码

    mysql> use mysql;
    update user set authentication_string=PASSWORD("你的密码") where user='root';
    update user set plugin="mysql_native_password";
    flush privileges;
    quit;
    service mysql restart

    这就可以用刚刚设置的root密码登录mysql了

    配置远程登录MySQL:

    mysql -u root -p

    use mysql;

    select user,host from user;

    发现默认的host都是localhost,

    修改root的host为'%',或新建一个用户

    方法一: 修改host,由localhost变为'%'

    grant all privileges on *.* to root @"%" identified by "此处改成你的MySQL密码";

    方法二:新建用户root2

    create user '这里换成你自定的账号'@'%' identified by '这里换成你自定的密码';

    成功会提示Query OK

    额外添加:

    有时候搭建服务需要连接数据库 ,老是提示 Access denied for user 'root'@'localhost'  咋也不知道什么原因。

    各种方法无效:对root授权:无效。修改root密码:无效。添加host:无效。

    只能这样解决了:

    grant all privileges on *.* to root@'localhost' identified by '密码';

    flush privileges;

    相关文章

      网友评论

          本文标题:Ubuntu1804安装并配置MySQL的远程登录

          本文链接:https://www.haomeiwen.com/subject/fghttctx.html