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

我不太熟悉服务器之类的工作,所以有人能告诉我问题是什么,以及如何解决它吗?
发布于 2018-06-25 18:32:44
检查您的mysql服务器是否正在运行,如果没有启用它。从终点站,
$ 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端口。
$ 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
检查您是否有根用户访问权限,在提示时输入密码。
$ mysql -u root -p如果您没有根访问权限或需要重置根密码,请按照这里中的步骤执行。这基本上是说最简单的方法是执行以下操作,并选择一个新的根密码。
$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: 现在,如果您只想连接到远程数据库,那么在创建mysql连接时,请指定主机和端口以及登录用户/密码。
如果遇到密码验证问题,可以考虑移动validate_password插件。
$ 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;https://askubuntu.com/questions/1049628
复制相似问题