1. 程式人生 > >MySQL8.0 配置筆記

MySQL8.0 配置筆記

今天把資料庫配置檔案修改了,結果重啟不了了

需要使用 mysqld --initialize 或 mysqld --initialize-insecure 命令來初始化資料庫

1、mysqld --initialize-insecure可以不生成隨機密碼,設定資料庫空密碼。

2、安裝Mysql時預設使用的是mysqld --initialize命令。這個命令也會生成一個隨機密碼。改密碼儲存在了Mysql的日誌檔案中

3、通過配置檔案檢視日誌檔案路徑  /etc/mysql/mysql.conf.d/mysqld.cnf。開啟該檔案,可以看到mysql的datadir和log檔案等的配置資訊

# 日誌檔案路徑 log-error       = /var/log/mysql/error.log

4、開啟log檔案並搜尋 password ,可以看到密碼

5、登入資料庫

使用找到的隨機密碼登入mysql,首次登入後,mysql要比必須修改預設密碼,否則不能執行任何其他資料庫操作,這樣體現了不斷增強的Mysql安全性。

這裡會有幾個問題

1、提示必須的修改密碼

2、8.0修改密碼命令

ALTER user 'root'@'localhost' IDENTIFIED BY 'Tinywan123456'

  

建立新使用者
MySQL8.0取消了直接grant建立使用者的語法,只能先create user再grant,因此建立root如下

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> create user user00[email protected]'localhost' identified by '112233';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> create user 
[email protected]
'%' identified by '112233'; Query OK, 0 rows affected (0.01 sec) mysql> FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)

測試user001遠端登入

$ mysql -u user001 -p112233 -h 159.11.213.20
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 35
Server version: 8.0.12 MySQL Community Server - GPL

Copyright (c) 2000, 2018, 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> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
+--------------------+
1 row in set (0.00 sec)

mysql>

 

Navicat Premium 遠端連線不了

提示一下資訊

如何解決:

1、先通過命令列進入mysql的root賬戶

mysql -h localhost -uroot -pTinywan123456

2、更改加密方式

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password' PASSWORD EXPIRE NEVER;
Query OK, 0 rows affected (0.10 sec)

3、修改密碼

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

4、清除快取

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.28 sec)

5、重新連線Navicat Premium  可以正常連線成功  

  

參考:

1、https://www.jb51.net/article/140282.htm

2、https://www.jb51.net/article/47727.htm

3、https://blog.csdn.net/zonghua521/article/details/78198052

4、https://blog.csdn.net/tr1912/article/details/81271851