首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数据库连接错误

问数据库连接错误
EN

Ask Ubuntu用户
提问于 2018-06-25 16:32:12
回答 1查看 8.2K关注 0票数 0

我从未使用过Ubuntu,现在我安装了Ubuntu18.04,而且我在连接数据库时遇到了问题。

我不太熟悉服务器之类的工作,所以有人能告诉我问题是什么,以及如何解决它吗?

EN

回答 1

Ask Ubuntu用户

发布于 2018-06-25 18:32:44

检查您的mysql服务器是否正在运行,如果没有启用它。从终点站,

代码语言:javascript
复制
$ sudo systemctl enable mysql

Synchronizing state of mysql.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mysql

$ sudo systemctl status mysql

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-06-25 10:23:56 PDT; 56min ago
 Main PID: 1364 (mysqld)
    Tasks: 28 (limit: 4915)
   CGroup: /system.slice/mysql.service
           └─1364 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

检查你是否让它听3306端口。

代码语言:javascript
复制
$ sudo netstat -plunt

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      1364/mysqld   

如果没有,您将不得不修改/etc/mysql/mysql.conf.d/mysqld.cnf

检查您是否有根用户访问权限,在提示时输入密码。

代码语言:javascript
复制
$ mysql -u root -p

如果您没有根访问权限或需要重置根密码,请按照这里中的步骤执行。这基本上是说最简单的方法是执行以下操作,并选择一个新的根密码。

代码语言:javascript
复制
$ sudo mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root: 

现在,如果您只想连接到远程数据库,那么在创建mysql连接时,请指定主机和端口以及登录用户/密码。

如果遇到密码验证问题,可以考虑移动validate_password插件。

代码语言:javascript
复制
$ mysql -h localhost -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22-0ubuntu18.04.1 (Ubuntu)

Copyright (c) 2000, 2018, 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> uninstall plugin validate_password;
票数 1
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1049628

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档