$ dpkg -l | grep mysql
$ apt install mysql-server
$ netstat -nltp
$ ps -ef | grep mysql
此时登录提示: ERROR 1045 (28000): Access denied for user ‘root’@'localhost’
解决办法:
/etc/mysql/debian.cnf
,即可看到密码$ sudo cat debian.cnf
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host = localhost
user = debian-sys-maint
password = ApOiIr4jQa9lEXRC
socket = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host = localhost
user = debian-sys-maint
password = ApOiIr4jQa9lEXRC
socket = /var/run/mysqld/mysqld.sock
修改/etc/mysql/mysql.conf.d/mysqld.cnf,添加如下内容
validate_password.check_user_name = OFF
validate_password.dictionary_file =
validate_password.length = 6
validate_password.mixed_case_count = 0
validate_password.number_count = 0
validate_password.policy = LOW
重启服务
$ systemctl restart mysql
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to restart 'mysql.service'.
Authenticating as: user
Password:
==== AUTHENTICATION COMPLETE ===
$ mysql -u debian-sys-maint -pApOiIr4jQa9lEXRC
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 8.0.17-0ubuntu2 (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>
mysql>
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
mysql> Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
mysql> Query OK, 0 rows affected (0.00 sec)
$ mysql -u root -p123456
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | localhost |
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
mysql> update user set host='%' where user='root';
mysql> select user,host from mysql.user;
+------------------+-----------+
| user | host |
+------------------+-----------+
| root | % |
| debian-sys-maint | localhost |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
+------------------+-----------+
修改/etc/mysql/mysql.conf.d/mysqld.cnf,修改绑定地址为0.0.0.0
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
bind-address = 0.0.0.0
$ systemctl restart mysql.service