美文网首页
2019-03-24 Linux安装MySQL

2019-03-24 Linux安装MySQL

作者: Darker_坤 | 来源:发表于2019-03-24 23:13 被阅读0次

一、安装

sudo apt update 

sudo apt-get install mysql-server  # 安装MySQL服务端

以上两个命令 即安装成功

二、安装后的密码问题

sudo cat /etc/mysql/debian.cnf 查看默认的用户名和密码

三、添加自己的密码

1、use mysql; 然后敲回车

2、update user set authentication_string=password("你的密码") where user="root"; 然后敲回车

3、flush privileges; 然后敲回车

用账户密码登录时发现报错

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

解决方法如下:

step1:在ubuntu的terminal(也即终端)上输入:

        sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf,

        进入到这个配置文件,

        然后在这个配置文件中的[mysqld]这一块中加入skip-grant-tables这句话。

        保存:wq,退出。输入:service mysql restart,重新启动mysql。

step2:在终端上输入mysql -u root -p,遇见输入密码的提示直接回车即可,进入mysql后,分别执行下面三句话:

        1、use mysql; 然后敲回车

        2、update user set authentication_string=password("你的密码") where user="root"; 然后敲回车

        3、flush privileges; 然后敲回车

step3:重新进入到mysqld.cnf文件中去把刚开始加的skip-grant-tables这条语句给注释掉。

            再返回终端输入mysql -u root -p,应该就可以进入数据库了。

step4:如果此时还是报出错误,那么就需要返回step3中,把注释掉的那条语句重新生效(就是删除#符号),重新进入mysql中,先选择一个数据库(use mysql;),然后输入select user,plugin from user;,看下图:

从图中可以看到在执行了select user,plugin from user;后,错误原因是因为plugin root的字段是auth_socket,那我们改掉它为下面的mysql_native_password就行了。输入:

1、update user set authentication_string=password("你的密码"),plugin='mysql_native_password' where user='root';

最后quit退出。返回执行step3。

那么这个问题就完全解决了

参考链接:https://www.cnblogs.com/cpl9412290130/p/9583868.html

相关文章

网友评论

      本文标题:2019-03-24 Linux安装MySQL

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