JDBC連接數(shù)據(jù)庫時出現(xiàn)的Public Key Retrieval is not allowed錯誤

關(guān)于JDBC連接數(shù)據(jù)庫時出現(xiàn)的Public Key Retrieval is not allowed錯誤

連接數(shù)據(jù)庫的url中,加上allowPublicKeyRetrieval=true參數(shù),經(jīng)過驗(yàn)證解決該問題。

image.png
image.png
image.png

mac下MySql啟動連接報(bào)錯:Authentication plugin ‘caching_sha2_password’ cannot be loaded: dlopen(/usr/local/mysql/lib/plugin/caching_sha2_password.so, 2): image not found。

問題:在連接數(shù)據(jù)庫時不能加載‘caching_sha2_password’這個插件,也就是不能對身份驗(yàn)證。

解決方案:

1.打開系統(tǒng)偏好設(shè)置,找到mysql,點(diǎn)擊Initialize Database.

2.輸入你的新密碼,記住這個密碼,用于后期鏈接數(shù)據(jù)庫的登陸使用.

3.選擇‘Use legacy password‘.

4.重啟mysql服務(wù).

啟動MySQL服務(wù)

sudo /usr/local/MySQL/support-files/mysql.server start

停止MySQL服務(wù)

sudo /usr/local/mysql/support-files/mysql.server stop

重啟MySQL服務(wù)

sudo /usr/local/mysql/support-files/mysql.server restar

... ERROR! The server quit without updating PID file (/usr/local/mysql/data/philos.local.pid).

Mostly this is a permission issue

Step1: Check the error file first.

tail -f /usr/local/mysql/data/*.err
Step2: Do a complete shut down or kill the process. Confirm that no mysql process is running

mysqladmin -uroot shutdown
sudo killall mysqld 

ps -ef | grep mysql
Step3: Give permisiions

sudo chown -RL root:mysql /usr/local/mysql
sudo chown -RL mysql:mysql /usr/local/mysql/data
chmod -R 755 /usr/local/mysql/data
Step4: Start mysql
sudo mysql.server start
mysql -u root -p
Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

既然現(xiàn)在沒法登錄到數(shù)據(jù)庫中,改密碼和添加用戶等操作也無從談起。好在MySQL中還提供了一種免去密碼校驗(yàn)進(jìn)入數(shù)據(jù)庫的方法,我們就先使用這種方法登入到數(shù)據(jù)庫中。然后將默認(rèn)密碼替換掉,上面的問題就可以解決掉啦~具體操作如下(如果想要快速解決,可以直接看最下面的快速方案)

一、找到Mysql配置文件
這個操作,在不同平臺下對應(yīng)的不同的操作文件
mac系統(tǒng)中配置文件是mysql安裝目錄support_file下的my-default文件

MAC下安裝Mysql找不到my.cnf配置文件的問題,并自己創(chuàng)建my.cnf文件

1.在 /etc 新建 my.cnf 文件

sudo vim my.cnf
1
2.將如下配置內(nèi)容寫入到文件中

Example MySQL config file for medium systems.

This is for a system with little memory (32M - 64M) where MySQL plays

an important part, or systems up to 128M where MySQL is used together with

other programs (such as a web server)

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]
character-set-server=utf8
init_connect='SET NAMES utf8
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
key_buffer_size = 16M
max_allowed_packet = 1M
table_open_cache = 64
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
character-set-server=utf8
init_connect='SET NAMES utf8'

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

(via the "enable-named-pipe" option) will render mysqld useless!

skip-networking

Replication Master Server (default)

binary logging is required for replication

log-bin=mysql-bin

# binary logging format - mixed recommended  
binlog_format=mixed  

  # required unique id between 1 and 2^32 - 1  
  # defaults to 1 if master-host is not set  
  # but will not function as a master if omitted  
  server-id   = 1  

# Replication Slave (comment out master section to use this)  
#  
# To configure this host as a replication slave, you can choose between  
# two methods :  
#  
# 1) Use the CHANGE MASTER TO command (fully described in our manual) -  
#    the syntax is:  
#  
#    CHANGE MASTER TO MASTER_HOST=<host>, MASTER_PORT=<port>,  
#    MASTER_USER=<user>, MASTER_PASSWORD=<password> ;  
#  
#    where you replace <host>, <user>, <password> by quoted strings and  
#    <port> by the master's port number (3306 by default).  
#  
#    Example:  
#  
#    CHANGE MASTER TO MASTER_HOST='125.564.12.1', MASTER_PORT=3306,  
#    MASTER_USER='joe', MASTER_PASSWORD='secret';  
#  
# OR  
#  
# 2) Set the variables below. However, in case you choose this method, then  
#    start replication for the first time (even unsuccessfully, for example  
#    if you mistyped the password in master-password and the slave fails to  
#    connect), the slave will create a master.info file, and any later  
#    change in this file to the variables' values below will be ignored and  
#    overridden by the content of the master.info file, unless you shutdown  
#    the slave server, delete master.info and restart the slaver server.  
#    For that reason, you may want to leave the lines below untouched  
#    (commented) and instead use CHANGE MASTER TO (see above)  
#  
# required unique id between 2 and 2^32 - 1  
# (and different from the master)  
# defaults to 2 if master-host is set  
# but will not function as a slave if omitted  
#server-id       = 2  
#  
# The replication master for this slave - required  
#master-host     =   <hostname>  
#  
# The username the slave will use for authentication when connecting  
# to the master - required  
#master-user     =   <username>  
#  
# The password the slave will authenticate with when connecting to  
# the master - required  
#master-password =   <password>  
#  
# The port the master is listening on.  
# optional - defaults to 3306  
#master-port     =  <port>  
#  
# binary logging - not required for slaves, but recommended  
#log-bin=mysql-bin  

  # 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  
      default-character-set=utf8   

    [myisamchk]  
    key_buffer_size = 20M  
    sort_buffer_size = 20M  
    read_buffer = 2M  
    write_buffer = 2M  

      [mysqlhotcopy]  
      interactive-timeout

3.保存文件

mysql -u root

image.png

在MySQL 8.04前,執(zhí)行:SET PASSWORD=PASSWORD('[新密碼]');但是MySQL8.0.4開始,這樣默認(rèn)是不行的。因?yàn)橹埃琈ySQL的密碼認(rèn)證插件是“mysql_native_password”,而現(xiàn)在使用的是“caching_sha2_password”。

修改密碼

mysql> use mysql;

mysql> update user set password=PASSWORD('新密碼') where user="root";

set password for 'root'@'localhost’=password('新密碼');

mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密碼';
mysql> flush privileges;
mysql> quit

到這里root賬戶就已經(jīng)重置成新的密碼了。

image.png

Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException:

image.png

升級 10.12 Sierra 之后運(yùn)行 brew update會報(bào) /usr/local 無權(quán)寫入
10.12 之前 brew 使用 /usr/local 作為主目錄,目錄所有者是 user
更新10.12之后 /usr/local 這個目錄所有者變成了 root
Fix:
sudo chown -R $(whoami) /usr/local/sbin

之后再運(yùn)行 brew update 就能正常運(yùn)行,同時 Homebrew 已經(jīng)提供對 10.12的支持,更新后主目錄遷移到 /usr/local/Homebrew ,現(xiàn)在再把權(quán)限改回來

sudo chown -R $(whoami) /usr/local/sbin

image.png

可以看出redis服務(wù)器啟動成功,并在監(jiān)聽6379端口的網(wǎng)絡(luò)連接。
注意: 使用命令$ redis-server也可以啟動,此時并不會加載任何配置文件,使用的是程序中內(nèi)置(built-in)的默認(rèn)配置.

檢測redis服務(wù)器是否啟動
重新打開一個終端窗口,輸入命令
$ redis-cli ping
該終端輸出
pong
說明服務(wù)器運(yùn)作正常。

關(guān)閉redis
關(guān)閉redis有2種方法:
方法1
在執(zhí)行啟動命令的終端窗口使用ctrl+c,此時第一個窗口輸出

8773:M 11 Sep 21:46:26.581 # User requested shutdown...
8773:M 11 Sep 21:46:26.581 * Saving the final RDB snapshot before exiting.
8773:M 11 Sep 21:46:26.583 * DB saved on disk
8773:M 11 Sep 21:46:26.583 * Removing the pid file.
8773:M 11 Sep 21:46:26.583 # Redis is now ready to exit, bye bye...
然后在另外一個終端窗口執(zhí)行$ redis-cli ping,輸出
Could not connect to Redis at 127.0.0.1:6379: Connection refused
說明確實(shí)已關(guān)閉

方法2
在另外一個終端窗口執(zhí)行$ redis-cli shutdown,此時第一個窗口輸出

8773:M 11 Sep 21:46:26.581 # User requested shutdown...
8773:M 11 Sep 21:46:26.581 * Saving the final RDB snapshot before exiting.
8773:M 11 Sep 21:46:26.583 * DB saved on disk
8773:M 11 Sep 21:46:26.583 * Removing the pid file.
8773:M 11 Sep 21:46:26.583 # Redis is now ready to exit, bye bye...
然后在另外一個終端窗口執(zhí)行$ redis-cli ping,輸出
Could not connect to Redis at 127.0.0.1:6379: Connection refused
說明確實(shí)已關(guān)閉

brew search nginx


image.png

有關(guān)brew常用的指令如下:

  1. brew搜索軟件命令: brew search nginx
  2. brew安裝軟件命令: brew install nginx
  3. brew卸載軟件命令: brew uninstall nginx
  4. brew升級命令: sudo brew update
  5. 查看安裝信息(比如查看安裝目錄等) sudo brew info nginx
  6. 查看已經(jīng)安裝的軟件:brew list

brew info nginx

image.png
image.png

nginx 是一款具有高負(fù)載能力的 web 服務(wù)器,也是 LNMP 架構(gòu)的主要角色之一。現(xiàn)在越來越多的開發(fā)者選擇 nginx 作為 php 的好搭檔,替代 apache 的位置。下面我以 Mac 系統(tǒng)為例,介紹下 nginx 的配置

基本配置
打開 nginx.conf,找到 http 下的 server,前幾行的內(nèi)容分別是:

listen 8080; #監(jiān)聽端口
server_name localhost; #本地域名
root /usr/local/var/www; #項(xiàng)目根目錄
nginx 默認(rèn)監(jiān)聽8080端口,你可以改成 80 端口。默認(rèn)項(xiàng)目根目錄也可以更改。不過更改之后要重新載入配置文件才能生效:

sudo nginx -s reload
注意:如果你不喜歡localhost,你想要一個個性的本地域名,比如www.test.com,首先要編輯 hosts 文件:

sudo vim /etc/hosts
添加一條:

127.0.0.1 www.test.com
然后修改 nginx.conf:

server_name www.test.com
總之 nginx.conf 中設(shè)置的域名,必須在 hosts 文件中存在!

常用命令
查看版本,以及配置文件地址
nginx -V
查看版本
nginx -v
指定配置文件
nginx -c filename
幫助
nginx -h
重新加載配置|重啟|停止|退出 nginx
nginx -s reload|reopen|stop|quit
-打開 nginx

sudo nginx
測試配置是否有語法錯誤
nginx -t
文件說明
/usr/local/etc/nginx/nginx.conf (配置文件路徑)

/usr/local/var/www (服務(wù)器默認(rèn)路徑)

/usr/local/Cellar/nginx/1.8.0 (安裝路徑
修改nginx默認(rèn)端口號
cd /usr/local/etc/nginx/nginx.conf

隱藏入口文件
在我們開發(fā)項(xiàng)目的時候,一般會有隱藏入口文件的需求。依然是在 http 下的 server,我們找到location /,在大括號內(nèi)做修改。切記ci框架和tp框架的寫法稍有不同,具體如下:

location / {
index index.php index.html index.htm;
if (!-e request_filename) { rewrite ^/(.*) /index.php?1 last; #ci框架寫法 #rewrite ^/(.*) /index.php?s=/$1 last; #tp框架寫法
break;
}
}
如果你用的是tp5, 入口文件在 public 目錄下,但是你不想在URL中寫localhost/public/訪問入口文件,你想直接通過localhost/訪問,你可以這樣寫:

rewrite ^/(.*)/public/index.php?s=/1 last;
其實(shí)隱藏入口文件就是 nginx 做了下路由,看懂它的正則,其實(shí)不難理解。

多站點(diǎn)設(shè)置
前面我們修改配置文件的代碼位置,都是在 http 下的 server 里。其實(shí)一個 server 就相當(dāng)于一個站點(diǎn)。nginx.conf 下 http 模塊默認(rèn)開啟一個 server,就是只有一個站點(diǎn)。如果我們要多站點(diǎn),就需要添加多個 server。

現(xiàn)在我們要添加一個站點(diǎn),假設(shè)這個站點(diǎn)的域名是 www.test2.com, 但是 server 不寫在 nginx.conf 里。nginx 為我們提供了存放多站點(diǎn)配置文件的目錄,我們切換到這個目錄:

cd /usr/local/etc/nginx/servers/
然后新建配置文件:

vim www.test2.com.conf
里邊寫一個 server:

server {

listen  80;
server_name  www.test2.com;

index  index.html index.php;

root  /usr/local/var/test2;

location / {
     index  index.php index.html;
     rewrite ^/(.*)$ /public/index.php?s=/$1 last;
     break;
}

location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

    fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
    fastcgi_param  PATH_INFO  $fastcgi_path_info;
    fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
    include        fastcgi_params;
}

}
保存退出,重新載入配置文件。最后在 hosts 中添加:

127.0.0.1 www.test2.com
此時,www.test2.com 就可以訪問到你的新項(xiàng)目目錄 /usr/local/var/test2下了!

反向代理設(shè)置
我的應(yīng)用場景是這樣的。假設(shè)我的服務(wù)器上存放著一個 node 項(xiàng)目,node 占用著80端口,可以正常運(yùn)行。但是我想再放一個 php 項(xiàng)目,此時這個php項(xiàng)目就不能是80端口了。如果想 node 項(xiàng)目和 php 項(xiàng)目均適用80端口,則需要利用 nginx 做反向代理設(shè)置。

解決方案是,node 項(xiàng)目設(shè)置成非 80 端口,比如3000,nginx 添加一個站點(diǎn),假設(shè)是www.test3.com,訪問 80 端口,代理到 3000 端口即可。

設(shè)置方法如上一節(jié)添加新站點(diǎn):

cd /usr/local/etc/nginx/servers/
然后新建配置文件:

vim www.test3.com.conf
寫入一個 server:

server {
listen 80;
server_name www.test3.com;
location / {
proxy_pass http://127.0.0.1:3000;
}
}
訪問 www.test3.com,就可以訪問到 node 項(xiàng)目了!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容