Ubuntu18 安裝 MySQL 8.0.22

Ubuntu18 安裝 MySQL 8.0.22

網上教程都比舊,也不是第一次安裝了,但依然仍是花了比較多的時間,特此記錄本次安裝過程。因是安裝完畢後回憶記錄,或有錯漏。mysql

第一步:sql

下載 mysql apt 配置文件: https://dev.mysql.com/downloads/repo/apt/ubuntu

第二步:socket

啓動 mysql 配置: sudo dpkg -i mysql-apt-config_0.8.16-1_all.deb, 文件名稱可能會變化。ui

第三步rest

選擇 MySQL Server & Cluster, 回車,繼續選擇 mysql 8, 回到最開始的頁面後,下移選擇 "ok"code

第四步server

sudo apt-get update教程

第五步ip

安裝mysql: sudo apt-get install mysql-server

第六步

啓動mysql: service mysql start

第七步

進入MySQL: sudo mysql -u root -p

無需輸入密碼,直接回車。

第八步

可選,本人將 mysql 庫下 user 表 host, authentication_string 修改成 "%", "123"

use mysql;
update user set host='%',authentication_string='123' where user='root';
flush privileges;

修改後查看 user 用戶信息:

select user,host,authentication_string,plugin from user where user = 'root' \G;
*************************** 2. row ***************************
                 user: root
                 host: %
authentication_string: 123
               plugin: auth_socket

第九步

修改 /etc/mysql/mysql.conf.d/mysqld.cnf 文件, 在 "[mysqld]" 下增長參數:

bind-address = 0.0.0.0
port=3306
# skip-grant-tables

並重啓 mysql。

重啓 mysql: service mysql restart

查看 mysql 狀態: service mysql status

中止mysql: service mysql stop

啓動mysql: service mysql start

第十步

發現登陸 mysql 必須使用 sudo, workbench鏈接不上,打算建立新用戶來解決問題:

// 建立新用戶, 發現報錯, 密碼不符合要求,打算修改密碼校驗規則
CREATE USER 'tony'@'%' IDENTIFIED BY '123';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
// 查看密碼校驗規則, 展現的密碼規則是修改後的規則
mysql> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name                        | Value  |
+--------------------------------------+--------+
| validate_password_check_user_name    | ON     |
| validate_password_dictionary_file    |        |
| validate_password_length             | 3      |
| validate_password_mixed_case_count   | 0      |
| validate_password_number_count       | 0      |
| validate_password_policy             | MEDIUM |
| validate_password_special_char_count | 0      |
+--------------------------------------+--------+
// 修改密碼校驗規則全局變量
set global validate_password_length=3;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=0;
set global validate_password_special_char_count=0;
// 從新建立用戶,任何地方均可鏈接: '%', 密碼: '123'
CREATE USER 'tony'@'%' IDENTIFIED BY '123';
// 授予全部權限,並刷新
GRANT ALL PRIVILEGES ON * . * TO 'tony'@'%';
flush privileges;

再次使用 WorkBench 能鏈接上了。

查看用戶 "tony" 信息:

*************************** 1. row ***************************
                 user: tony
                 host: %
authentication_string: *23AE809DDACAF96AF0FD78ED04B6A265E05AA257
               plugin: mysql_native_password
*************************** 2. row ***************************

登陸mysql:

mysql -u tony -p
password: 123
相關文章
相關標籤/搜索