MySQL 新安装:用户访问被拒绝

MySQL 新安装:用户访问被拒绝

安装前

wolf@Linux:~$ service mysql status
Unit mysql.service could not be found.
wolf@Linux:~$ 

安装 ...

wolf@Linux:~$ sudo apt install mysql-server
Reading package lists... Done

安装后

wolf@Linux:~$ service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Sat 2020-05-29 11:33:26 +08; 10s ago
 Main PID: 4219 (mysqld)
    Tasks: 28 (limit: 1129)
   CGroup: /system.slice/mysql.service
           └─4219 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

Mei 29 11:33:26 Linux1 systemd[1]: Starting MySQL Community Server...
Mei 29 11:33:26 Linux1 systemd[1]: Started MySQL Community Server.
wolf@Linux:~$ 

仍然无法访问

wolf@Linux:~$ mysql
ERROR 1045 (28000): Access denied for user 'wolf'@'localhost' (using password: NO)
wolf@Linux:~$ 

/var/log/mysql/error.log

2020-05-29T04:29:04.188484Z 3 [Note] Access denied for user 'wolf'@'localhost' (using password: NO)

即使使用 root 用户

wolf@Linux:~$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
wolf@Linux:~$ 

wolf@Linux:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
wolf@Linux:~$ 

/var/log/mysql/error.log

2020-05-29T04:30:01.312977Z 4 [Note] Access denied for user 'root'@'localhost'
2020-05-29T04:30:15.223701Z 5 [Note] Access denied for user 'root'@'localhost'

重置 root 密码

wolf@Linux:~$ sudo mysqladmin -u root password NEWPASSWORD
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
wolf@Linux:~$ 

重置新密码时,/var/log/mysql/error.log 没有新日志

但没用

wolf@Linux:~$ mysql -u root -pNEWPASSWORD
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
wolf@Linux:~$ 

/var/log/mysql/error.log

2020-05-29T04:32:35.609239Z 8 [Note] Access denied for user 'root'@'localhost'

尝试不使用密码访问也失败了

wolf@Linux:~$ sudo mysqld_safe --skip-grant-tables &
[1] 5489
wolf@Linux:~$ 2020-05-30T03:43:42.913712Z mysqld_safe Logging to syslog.
2020-05-30T03:43:42.916500Z mysqld_safe Logging to '/var/log/mysql/error.log'.
2020-05-30T03:43:42.918902Z mysqld_safe Directory '/var/run/mysqld' for UNIX socket file don't exists.

[1]+  Exit 1                  sudo mysqld_safe --skip-grant-tables
wolf@Linux:~$ 

当 /var/log/mysql/error.log 没有新日志时sudo mysqld_safe --skip-grant-tables &

更新安装期间的 /var/log/mysql/error.log

wolf@Linux:/var/log/mysql$ tail -F error.log 
2020-05-30T04:28:13.132939Z 0 [Warning] CA certificate ca.pem is self signed.
2020-05-30T04:28:13.132959Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2020-05-30T04:28:13.133002Z 0 [Note] Server hostname (bind-address): '127.0.0.1'; port: 3306
2020-05-30T04:28:13.133009Z 0 [Note]   - '127.0.0.1' resolves to '127.0.0.1';
2020-05-30T04:28:13.133027Z 0 [Note] Server socket created on IP: '127.0.0.1'.
2020-05-30T04:28:13.137509Z 0 [Note] Event Scheduler: Loaded 0 events
2020-05-30T04:28:13.137601Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2020-05-30T04:28:13.138071Z 0 [Note] InnoDB: Buffer pool(s) load completed at 200530 12:28:13
2020-05-30T04:28:13.138126Z 0 [Note] /usr/sbin/mysqld: ready for connections.
Version: '5.7.30-0ubuntu0.18.04.1'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  (Ubuntu)

下一步我应该做什么?

相关内容