mysql5.7升级至mysql8.0.17

系统mac 10.14.3

安装: brew install mysql

问题1:mysql服务起不来

1.1 报错:

ERROR! The server quit without updating PID file(/usr/local/var/mysql/MAC-OF-BPDJ-ZP.local.pid

1.2 解决:

重新命名数据文件 mv /usr/local/var/mysql /usr/local/var/mysql_bak

1.3 具体操作如下
1.启动 mysql
➜  support-files sudo /usr/local/Cellar/mysql/8.0.17/support-files/mysql_server start
Starting MySQL
....... ERROR! The server quit without updating PID file (/usr/local/var/mysql/MAC-OF-BPDJ-ZP.local.pid).

2.报错
/usr/local/var/mysql
/usr/local/Cellar/mysql/8.0.17/support-files/mysql.server start

3.删除 rm mysql-bin.000001 - rm mysql-bin.000011

4.直接重命名文件夹 mv /usr/local/var/mysql /usr/local/var/mysql_bak

5.卸载mysql: brew uninstall mysql
➜  var brew uninstall mysql
Uninstalling /usr/local/Cellar/mysql/8.0.17... (284 files, 272.5MB)

6.重新安装mysql: brew install mysql
➜  local brew install mysql
Updating Homebrew...
Ignoring path homebrew-cask/
To restore the stashed changes to /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask run:
  'cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask && git stash pop'
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core and homebrew/cask).
==> Updated Formulae
libpq ✔           libpqxx           postgresql@10     [email protected]    tor
jenkins           postgresql        [email protected]    rke               ucloud

==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.17.mojave.bottle.tar.gz
Already downloaded: /Users/b_tt/Library/Caches/Homebrew/downloads/45d08ca8020b5abe52a5de9fb782dae5f34e6790f9664049b863fd02a404f947--mysql-8.0.17.mojave.bottle.tar.gz
==> Pouring mysql-8.0.17.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.17/bin/mysqld --initialize-insecure --user=b_tt --basedir
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall mysql`
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To have launchd start mysql now and restart at login:
  brew services start mysql
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
  /usr/local/Cellar/mysql/8.0.17: 284 files, 272.5MB

7.查看mysql配置文件在哪里:mysql --help|grep 'my.cnf'
➜  /etc mysql --help|grep 'my.cnf'
                      order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

8.查看mysql:brew info mysql
1.4 参考文章 https://cloud.tencent.com/developer/article/1339287

问题2 MySQL 启动成功但未监听3306

2.1 现象:ps aux | grep mysql有进程,lsof -i -n -P | grep :3306没有监听3306端口
➜  mysql ps aux | grep mysql
b_tt              8535   0.0  0.0  4277236    540 s002  R+    3:06下午   0:00.00 grep --color=auto --exclude-dir=.bzr --exclude-dir=CVS --exclude-dir=.git --exclude-dir=.hg --exclude-dir=.svn mysql
b_tt              8364   0.0  3.9  4802876 327176   ??  S     2:58下午   0:01.93 /usr/local/opt/mysql/bin/mysqld --basedir=/usr/local/opt/mysql --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/opt/mysql/lib/plugin --log-error=MAC-OF-BPDJ-ZP.local.err --pid-file=MAC-OF-BPDJ-ZP.local.pid --socket=/tmp/mysql.sock --port=3307
b_tt              8073   0.0  0.0  4279864   1236   ??  S     2:58下午   0:00.05 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --datadir=/usr/local/var/mysql
➜  mysql lsof -i -n -P | grep :3306
2.2 解决 注释掉配置文件的 skip-grant-tables和skip-networking两个选项,重启服务
2.3 参考文档https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
官方手册有这样的一句话:
如有必要,请停止MySQL服务器,然后使用该--skip-grant-tables 选项重新启动它
这使得任何人都可以在没有密码和所有权限的情况下进行连接,
并禁用帐户管理语句,例如 ALTER USER和 SET PASSWORD。
因为这是不安全的,如果使用该--skip-grant-tables 选项启动服务器 ,
它会--skip-networking 自动启用 以防止远程连接。

PS:说明 开启 skip-grant-tables 会自动启用skip-networking

问题3 命令行可以登录(mysql -u root -p),但是客户端sequel pro登录不了

3.1 设置root密码
3.2 解决
B.4.3.2.3重置Root密码:通用指令
前面几节提供了专门针对Windows和Unix以及类Unix系统的密码重置说明。或者,在任何平台上,您都可以使用mysql客户端重置密码(但这种方法不太安全):

1.如有必要,请停止MySQL服务器,然后使用该--skip-grant-tables 选项重新启动它。这使得任何人都可以在没有密码和所有权限的情况下进行连接,并禁用帐户管理语句,例如 ALTER USER和 SET PASSWORD。因为这是不安全的,如果使用该--skip-grant-tables 选项启动服务器 ,它会--skip-networking 自动启用 以防止远程连接。
启动服务:
shell> /usr/local/opt/mysql/bin/mysql.server start --skip-grant-tables

2.使用mysql客户端连接MySQL服务器 ; 没有密码是必需的,因为服务器启动时 --skip-grant-tables:
shell> mysql

3.在mysql客户端中,告诉服务器重新加载授权表,以便帐户管理语句起作用:
mysql> FLUSH PRIVILEGES;

4.然后更改'root'@'localhost' 帐户密码。将密码替换为您要使用的密码。要更改root具有不同主机名部分的帐户的密码 ,请修改使用该主机名的说明。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

您现在应该能够root使用新密码连接到MySQL服务器 。停止服务器并正常重新启动它(没有 --skip-grant-tables和 --skip-networking选项)。

到此为止 命令行可以用 mysql -u root -p root登录(原来的密码是空)
3.3 参考官方手册:[https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html](https://dev.mysql.com/doc/refman/8.0/en/resetting-permissions.html
3.4 客户端sequal pro依然登录不上去 报错Authentication plugin 'caching_sha2_password' cannot be loaded: dlopen(/usr/local/lib/plugin...
3.5 解决 ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY '用户root的登录密码';
➜  /etc mysql -u root -p root
Enter password: root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 8.0.17 Homebrew

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> use mysql
Database changed
mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)

mysql>
mysql> ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY 'root';
Query OK, 0 rows affected (0.01 sec)

mysql> select user,host,plugin from user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | mysql_native_password |
+------------------+-----------+-----------------------+
4 rows in set (0.00 sec)
3.6 参考 https://blog.csdn.net/s634772208/article/details/81155068

你可能感兴趣的:(mysql5.7升级至mysql8.0.17)