ubuntu18.4安装mysql数据库以及登录

utuntu18.4安装mqsql数据库

  • 步骤一
    ctrl+alt+t打开终端窗口
    1,第一步,首先运行如下命令
    sudo apt-get update
    2,第二步,运行如下命令安装mysql数据库
    sudo apt-get install mysql-server mysql-client
    3,等待安装完成。。。

  • 步骤二
    1,当你初次在终端使用如下命令登录时
    mysql -hlocalhost -uroot -p
    然后输入密码可能会提示错误:ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’
    2,以上错误的原因是:由于使用命令sudo apt-get install mysql安装时,并没有提示输入密码,则密码没有初始化,使用root 用户登录自然失败.

  • 步骤三
    1,解决问题
    思路如下:
    1>在终端输入如下命令sudo gedit /etc/mysql/debian.cnf打开该文件
    其内容如下:
    # Automatically generated for Debian scripts. DO NOT TOUCH!
    [client]
    host = localhost
    user = debian-sys-maint
    password = oLK8hg5zRd4tjohT
    socket = /var/run/mysqld/mysqld.sock
    [mysql_upgrade]
    host = localhost
    user = debian-sys-maint
    password = oLK8hg5zRd4tjohT
    socket = /var/run/mysqld/mysqld.sock
    2>使用如上内容中的用户名密码登录mysql数据库
    mysql -hlocalhost -udebian-sys-maint -p 提示输入密码,密码为上面内容中的password
    3>使用如上方法就以登录上mysql数据库了
    4>接下来我们执行如下命令修改PLUGIN
    update mysql.user set authentication_string = password(123456), plugin='mysql_native_password' where user='root';
    5>重启mysql服务
    sudo /etc/init.d/mysql stop
    sudo /etc/init.d/mysql start
    6>最后我们就可以使用root用户登录mysql数据库了,如下:

wdhcr@wdhcr:~$ mysql -hlocalhost -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-0ubuntu0.18.04.1 (Ubuntu)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> `
  • 最后
    新手马农,互相学习,希望各位大佬多多指教。。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值