MySQL8.0.x Yum安裝和配置
一. yum安裝
1.先卸載機器和mysql有關的東西,有的安裝了mariab-lib,會對安裝有干擾,卸載了它。
[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
2.卸載命令
yum erase -y mariadb-libs-5.5.60-1.el7_5.x86_64
二. 安裝mysql 8.0 社區版yum倉庫
1.官方網站
https://dev.mysql.com/downloads/repo/yum/
2.下載倉庫包
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
3.安裝倉庫
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
4.安裝mysql 8.0版
yum install -y mysql-community-{server,client,common,libs}-*
5.啓動mysql 8.0
systemctl start mysqld
systemctl enable mysqld
6.查看初始日誌,'password'字段找到臨時密碼
查看日誌,找到臨時密碼,這裏還一個問題,日誌這個時間不正確,與本地差好幾個小時呢 ,這個在安裝完了,再調下。
[root@localhost ~]# tailf /var/log/mysqld.log
2019-01-12T13:59:34.558708Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server in progress as process 7038
2019-01-12T13:59:36.873412Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: :ZSytWyMp6Q>
2019-01-12T13:59:38.113827Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has completed
2019-01-12T13:59:39.798256Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 7085
2019-01-12T13:59:40.949981Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-01-12T13:59:41.019836Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-01-12T13:59:41.190008Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
這個就啓動了 第二行 最後那個就是密碼
7.登錄
把那個臨時密碼輸入進去,就可以登錄了
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13
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>
8.修改臨時密碼
跟之前的版本不一樣,得把臨時密碼給改了,之前set password=password('mima') 這個命令已經不好使了
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
yum 安裝還有一個問題,就是密碼還有複雜性要求,這東西策略我還不知道怎麼改
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'dgdB20I5!@#';
Query OK, 0 rows affected (0.02 sec)
mysql>
用新密碼重新登錄就行了
9.修改日誌時間問題
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2019-01-12 22:22:19 |
+---------------------+
1 row in set (0.00 sec)
mysql> SHOW GLOBAL VARIABLES LIKE 'log_timestamps';
+----------------+-------+
| Variable_name | Value |
+----------------+-------+
| log_timestamps | UTC |
+----------------+-------+
1 row in set (0.00 sec)
mysql> SET GLOBAL log_timestamps = SYSTEM;
Query OK, 0 rows affected (0.00 sec)
mysql> SHOW GLOBAL VARIABLES LIKE 'log_timestamps';
+----------------+--------+
| Variable_name | Value |
+----------------+--------+
| log_timestamps | SYSTEM |
+----------------+--------+
1 row in set (0.00 sec)
mysql> exit
且默認安裝後error_log,slow_log 日誌時間戳默認爲UTC,因此會造成與系統時間不一致,與北京時間相差8個小時
因爲log_timestamps 是一個GLOBAL的全局參數,所以直接在登錄後去set全局參數,重啓後就會直接失效
因此需要在mysql的配置文件中[mysqld]中增加一條log_timestamps的配置
vim /etc/my.cnf
[mysqld]
log_timestamps=SYSTEM
重啓下MySQL
systemctl restart mysqld
再查看下日誌,果然時間就對了
[root@localhost ~]# tailf /var/log/mysqld.log
2019-01-12T13:59:38.113827Z 0 [System] [MY-013170] [Server] /usr/sbin/mysqld (mysqld 8.0.13) initializing of server has completed
2019-01-12T13:59:39.798256Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 7085
2019-01-12T13:59:40.949981Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-01-12T13:59:41.019836Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-01-12T13:59:41.190008Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2019-01-12T22:29:25.655750+08:00 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.13) MySQL Community Server - GPL.
2019-01-12T22:29:26.338014+08:00 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.13) starting as process 24698
2019-01-12T22:29:26.856796+08:00 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2019-01-12T22:29:26.878264+08:00 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.13' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server - GPL.
2019-01-12T22:29:27.007610+08:00 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
10.修改MySQL數據目錄位置
a.查詢MySQL 8.0默認數據目錄
mysql> show variables like '%dir%';
+-----------------------------------------+--------------------------------+
| Variable_name | Value |
+-----------------------------------------+--------------------------------+
| basedir | /usr/ |
| binlog_direct_non_transactional_updates | OFF |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
| datadir | /var/lib/mysql/ |
| innodb_data_data_dir | |
| innodb_directories | |
| innodb_log_group_data_dir | ./ |
| innodb_max_dirty_pages_pct | 90.000000 |
| innodb_max_dirty_pages_pct_lwm | 10.000000 |
| innodb_temp_tablespaces_dir | ./#innodb_temp/ |
| innodb_tmpdir | |
| innodb_undo_directory | ./ |
| lc_messages_dir | /usr/share/mysql-8.0/ |
| plugin_dir | /usr/lib64/mysql/plugin/ |
| slave_load_tmpdir | /tmp |
| tmpdir | /tmp |
+-----------------------------------------+--------------------------------+
16 rows in set (0.00 sec)
顯而易見,datadir在 /var/lib/myql
b.先把MySQL停下來
systemctl stop mysqld
c.創建數據目錄,複製數據文件(加入我把數據目錄放到/data/下)
mkdir -p /data/mysql_data
cp -r /var/lib/mysql/* /data/mysql_data/
chown -R mysql:mysql /data/mysql_data
d.編輯配置文件
vim /etc/my.cnf
datadir=/data/mysql_data
socket=/data/mysql_data/mysql.sock
#下面這得加上,不然服務能起來,你客戶端不能登錄
[mysql]
socket=/data/mysql_data/mysql.sock
e.啓動並查詢
systemctl start mysqld
[root@localhost my.cnf.d]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13 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 variables like '%dir%';
+-----------------------------------------+--------------------------------+
| Variable_name | Value |
+-----------------------------------------+--------------------------------+
| basedir | /usr/ |
| binlog_direct_non_transactional_updates | OFF |
| character_sets_dir | /usr/share/mysql-8.0/charsets/ |
| datadir | /data/mysql_data/ |
| innodb_data_data_dir | |
| innodb_directories | |
| innodb_log_group_data_dir | ./ |
| innodb_max_dirty_pages_pct | 90.000000 |
| innodb_max_dirty_pages_pct_lwm | 10.000000 |
| innodb_temp_tablespaces_dir | ./#innodb_temp/ |
| innodb_tmpdir | |
| innodb_undo_directory | ./ |
| lc_messages_dir | /usr/share/mysql-8.0/ |
| plugin_dir | /usr/lib64/mysql/plugin/ |
| slave_load_tmpdir | /tmp |
| tmpdir | /tmp |
+-----------------------------------------+--------------------------------+
16 rows in set (0.01 sec)
11.mysql免密碼登錄
直接在[mysql]下面添加root password就行了
vim /etc/my.cnf
[mysql]
user='root'
password='dgdB20I5!@#'
下次直接輸入mysql就可以登錄了,方便的很,生產環境謹慎使用
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.13 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> exit
Bye
12.配置MySQL遠程連接配置
[root@localhost ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 8.0.13 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> 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> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$LP^CZmMk
T4'S0<pcrj0ol yi9p7igi1q59wifpwx="" 93nrizez4gboepk="" |="" caching_sha2_password="" +-----------+------------------+------------------------------------------------------------------------+-----------------------+="" 4="" rows="" in="" set="" (0.00="" sec)="" mysql="">
這裏看到都是localhost,所以還不能遠程連接
root賬戶爲默認的密碼加密方式是:caching_sha2_password;而現在很多客戶端工具還不支持這種加密認證方式,連接測試的時候就會報錯:client does not support authentication protocol requested by server; consider upgrading MySQL client,這裏的錯誤信息就是不支持身份認證方式 新創建的用戶有效,老用戶還是不行的
所以,我們需要修改下配置文件,修改下默認加密方式,在[mysqld]下面添加一行default-authentication-plugin=mysql_native_password
vim /etc/my.cnf
[mysqld]
default-authentication-plugin=mysql_native_password
重啓MySQL
systemctl restart mysqld
修改用戶遠程訪問權限
mysql> grant all on *.* to 'root'@'%' identified by 'Zhang87073!';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by 'Zhang87073!'' at line 1
MySQL 8.0 這裏報錯了。。。之前的版本都是這樣一行就搞定了 。。。所以 。。。
#這裏先創建一個用戶
mysql> create user 'root'@'%' identified by 'Zhang87073!';
Query OK, 0 rows affected (0.06 sec)
#在進行授權
mysql> grant all privileges on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.05 sec)
#再查看一下
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> select host, user, authentication_string, plugin from user;
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| host | user | authentication_string | plugin |
+-----------+------------------+------------------------------------------------------------------------+-----------------------+
| % | root | *43CAAB27D90B4E33EC75DEEFA02577F7E2BACE93 | mysql_native_password |
| localhost | mysql.infoschema | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.session | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | mysql.sys | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED | caching_sha2_password |
| localhost | root | $A$005$LP^CZmMk
T4'S0<pcrj0ol yi9p7igi1q59wifpwx="" 93nrizez4gboepk="" |="" caching_sha2_password="" +-----------+------------------+------------------------------------------------------------------------+-----------------------+="" 5="" rows="" in="" set="" (0.00="" sec)="" ```="" 遠程連接測試="" ![img](https:="" note.youdao.com="" yws="" public="" resource="" d145e6ad432f8fd5aa725ac2512d20e1="" xmlnote="" b596a539cecc43efb0ee0ea916094bed="" 20966)="" 4a62367ba7dd44799ec037386fd847e2="" 20968)="" ####="" 13.修改密碼策略="" yum="" 安裝的時候="" 遇到了密碼策略的問題,我查詢了一下,現在得到了答案,且發現二進制包安裝完,這個密碼策略是空的。="" #####="" a.查看當前的密碼策略="" mysql=""> SHOW VARIABLES LIKE 'validate_password%';
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
b.密碼策略的解釋
validate_password.check_user_name 這個參數用來檢查用戶名
validate_password_dictionary_file 字典文件
validate_password_length密碼長度的最小值(這個值最小要是4)。
validate_password_mixed_case_count大小寫的最少個數
validate_password_number_count 密碼中數字的最少個數
validate_password_policy 這個參數用於控制validate_password的驗證策略 0-->low 1-->MEDIUM 2-->strong。
validate_password_special_char_count 特殊字符的最小個數
c.修改密碼策略
舉個例子 知道怎麼搞就行了 (我覺得這東西還是複雜點沒壞處)
mysql > set global validate_password.policy=0;
mysql > set global validate_password.policy=0;
mysql > set global validate_password.length=4;
mysql > set global validate_password.check_user_name=OFF;
mysql > set global validate_password.number_count=0;
mysql > set global validate_password.special_char_count=0;
mysql > flush privileges;
mysql > ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'root' ;
mysql > update user set host='%' where user ='root';