收集一些window下MySQL相關(guān)的資料。
1.可視化工具無法連接 MySQL 8.0 的問題
MySQL 8.0 版本去除了 password 字段饥脑,改用 authentication_string 字段痕寓;同時(shí)還更改了加密方式清酥,之前版本的加密方式是「mysql_native_password」讶踪,8.0 之后的加密規(guī)則更改為「caching_sha2_password 」购公,這里需要把用戶密碼加密規(guī)則更改為原來的加密方式即可萌京。
# 假如
# 主機(jī)名為 localhost
# 數(shù)據(jù)庫用戶名為 root
# 數(shù)據(jù)庫密碼為 123456
# 則輸入以下指令
# 切換到 mysql 數(shù)據(jù)庫
use mysql;
# 設(shè)置用戶密碼永不過期
alter user root@localhost identified by '123456' password expire never;
# 用「mysql_native_password」加密方式更新 root 用戶密碼
alter user root@localhost identified with mysql_native_password by '123456';
# 刷新
flush privileges;
2. MySQL utf8 存入中文亂碼
從后臺(tái)讀取的數(shù)據(jù),數(shù)字和英文正常顯示宏浩,中文都是問號(hào)知残,很容易猜到可能是字符集的問題。
是MySQL 默認(rèn)字符集的問題比庄。
## 進(jìn)入 MySQL
mysql -u root -p
## 輸入密碼
## 查看各種默認(rèn)配置
show variables like '%char%';
## 會(huì)有一個(gè)表 大概如下
## 部分utf8 可能會(huì)是其他值求妹,然后我們慢慢修改
## set character_set_client=utf8
## 也可以用以上方法設(shè)置,但重啟 mysql 又會(huì)回到原點(diǎn)
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
## 退出數(shù)據(jù)庫
-------------------------------------------------------------
## my.ini
## 編輯這個(gè)配置文件
## 在對(duì)應(yīng)的區(qū)域添加佳窑、新增
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
## 重啟mysql服務(wù)