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> `
- 最后
新手马农,互相学习,希望各位大佬多多指教。。。。