一,在MySQL 8.0.11中,caching_sha2_password是默认的身份验证插件,而不是以往的mysql_native_password。有关此更改对服务器操作的影响以及服务器与客户端和连接器的兼容性的信息,请参阅caching_sha2_password作为首选的身份验证插件。(翻译自https://dev.mysql.com/doc/refman/8.0/en/caching-sha2-pluggable-authentication.html)
今天在Mac 上配置安装mysql8.0.11时,设置mysql密码,设置成功后在终端下输入mysql -u root -p,再输入密码能正常进入,但在phpmyadmin提示无法连接,具体报错信息为:
mysqli_real_connect(): The server requested authentication method unknown to the client [sha256_password]
解决方法:在mysql的配置文件上添加一些代码:要在[mysqld]位置上。但在mac上找不到my.conf文件。只能自己手动添加:
将加密方式改为旧的,在配置文件my.conf中添加如下:
[mysqld]
default_authentication_plugin=mysql_native_password
my.conf具体内容为下:
# Example MySQL config file for small systems. # # This is for a system with little memory (<= 64M) where MySQL is only used # from time to time and it's important that the mysqld daemon # doesn't use much resources. # # MySQL programs look for option files in a set of # locations which depend on the deployment platform. # You can copy this option file to one of those # locations. For information about these locations, see: # http://dev.mysql.com/doc/mysql/en/option-files.html # # In this file, you can use all long options that a program supports. # If you want to know which options a program supports, run the program # with the "--help" option. # The following options will be passed to all MySQL clients [client] default-character-set=utf8 #password = your_password port = 3306 socket = /tmp/mysql.sock # Here follows entries for some specific programs # The MySQL server [mysqld] default-storage-engine=INNODB character-set-server=utf8 collation-server=utf8_general_ci port = 3306 socket = /tmp/mysql.sock skip-external-locking key_buffer_size = 16K max_allowed_packet = 1M table_open_cache = 4 sort_buffer_size = 64K read_buffer_size = 256K read_rnd_buffer_size = 256K net_buffer_length = 2K thread_stack = 128K default_authentication_plugin= mysql_native_password # Don't listen on a TCP/IP port at all. This can be a security enhancement, # if all processes that need to connect to mysqld run on the same host. # All interaction with mysqld must be made via Unix sockets or named pipes. # Note that using this option without enabling named pipes on Windows # (using the "enable-named-pipe" option) will render mysqld useless! # #skip-networking server-id = 1 # Uncomment the following if you want to log updates log-bin=mysql-bin # binary logging format - mixed recommended #binlog_format=mixed # Causes updates to non-transactional engines using statement format to be # written directly to binary log. Before using this option make sure that # there are no dependencies between transactional and non-transactional # tables such as in the statement INSERT INTO t_myisam SELECT * FROM # t_innodb; otherwise, slaves may diverge from the master. #binlog_direct_non_transactional_updates=TRUE # Uncomment the following if you are using InnoDB tables #innodb_data_home_dir = /usr/local/mysql/data #innodb_data_file_path = ibdata1:10M:autoextend #innodb_log_group_home_dir = /usr/local/mysql/data # You can set .._buffer_pool_size up to 50 - 80 % # of RAM but beware of setting memory usage too high #innodb_buffer_pool_size = 16M #innodb_additional_mem_pool_size = 2M # Set .._log_file_size to 25 % of buffer pool size #innodb_log_file_size = 5M #innodb_log_buffer_size = 8M #innodb_flush_log_at_trx_commit = 1 #innodb_lock_wait_timeout = 50 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [myisamchk] key_buffer_size = 8M sort_buffer_size = 8M [mysqlhotcopy] interactive-timeout [mysqld] transaction-isolation=READ-COMMITTED
以上为my.cnf,具体内容。由于my.cnf 文件格式为ASCII编码,所以不能使用mac自带的文本编辑器。要使用mac 终端 sudo vi /etc/my.cnf。具体使用方法参考:https://blog.csdn.net/hjiaqing/article/details/93659273
关于将my.cnf放在哪里,可以参考资料:https://blog.csdn.net/thomas0713/article/details/82928020
Mac系统添加MySQL配置文件
在Mac系统中,安装完MySQL后,是没有自动生成MySQL的配置文件的,在网上查找说需要自己手动创建配置文件,但是说的都不是很详细,所以配置起来总是失败。之后自己翻看了官方文档以及相关资料,终于将配置文件配置成功了!与大家分享一下。
首先我们先看一下MySQL默认指定的my.cnf路径,使用命令
~~~
mysql --help|grep 'my.cnf'
~~~
这是四个默认的指定路径,MySQL从第一个路径依次去找my.cnf配置的文件,我们直接将my.cnf文件放在第一个路径下就可以了。
在配置my.cnf文件的时候,一开始我是使用Mac自带的文本编辑软件创建my.cnf文件,但是文件的编码格式是utf-8的,在MySQL读取的时候会报错,之后查找相关资料发现MySQL的配置文件需要时ASNI/ASCII格式的,所以我直接在终端中用vim命令直接创建了my.cnf文件,然后将配置写入,就可以了。
在添加完my.cnf后要重新启动mysql。可以在系统偏好设置里进行。
这些弄好之后要在终端里登入mysql。修改root 密码:
首先获得超级权限:sudo su
输入绝对路径 /usr/local/mysql/bin/mysql -u root -p
输入密码
退出:quit
参考文献:https://blog.csdn.net/weixin_41998715/article/details/82827928
把新的加密方式,改为旧的加密方式,而root用户也要进行相应的更改才可以,因为root用户还是新的加方式,所以使用alter语句改为重置密码来覆盖新的加密方式的密码:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
password是你将要设置的root用户的密码。
到这里就大功告成啦!可以登入phpmyadmin