1.mysql官方下載Linux版本,我這裏下載的是: mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz(注:不一樣壓縮包,存在解壓命令的不一樣)mysql
2.將壓縮包扔到Linux的 /usr/local文件夾中
3.使用解壓命令解壓: tar xvf /usr/local/mysql-8.0.22-linux-glibc2.12-x86_64.tar.xz
4.重命名解壓後獲得的文件夾, 名稱變動爲 mysql (mysql一些默認配置裏Linux訪問路徑爲:/usr/local/mysql, 直接重命名後,後續一些地方則不須要更改)linux
6.進入被重命名過的文件夾中,再建立一個文件夾,取名:data
(1) cd /usr/local/mysql
(2) mkdir datasql
7.建立 /etc/my.cnf . 看其餘博友說的,好像是8.0這個版本經過二進制文件解壓安裝的話是不存在的. 這裏手動建立一個數據庫
(1) vi /etc/my.cnfbash
(2)複製如下內容進去:
[mysqld]
port=3306
basedir=/usr/local/mysql
datadir=/data01/data
max_connections=10000
max_connect_errors=10
character-set-server=UTF8MB4
default-storage-engine=INNODB
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTIONide
文字說明:
(須要修改的地方:
basedir: 使用給定目錄做爲根目錄(安裝目錄)
datadir: 從給定目錄讀取數據庫文件,存儲mysql數據文件夾
重要的兩個:
lower_case_table_names: 值爲1,忽略大小寫,即查詢時候不分大小寫(一旦設置並啓動後,再更改比較煩,慎重)
sql_mode: (sql中select後面的字段必須出如今group by後面,或者被聚合函數包裹,否則會拋出上面的錯誤,容許使用 GROUP BY 函數)函數
(3)按鍵盤左上角 ESC鍵 -> :wq (保存文件)ui
8.進行受權
(1) chown -R mysql.mysql /usr/local/mysql
(2) chmod 755 /usr/local/mysql
(3) chmod 644 /etc/my.cnfthis
生成mysql基礎數據
(1) cd /usr/local/mysql/binspa
(2) 生成mysql數據庫基礎數據 ./mysqld --user=mysql --basedir=/usr/local/mysql --datadir=/data01/data --lower_case_table_names=1 --initialize
文字說明:
--user=mysql : 指定運行mysqld進程的用戶名。可更改,主要爲了後續添加多個mysql管理員時方便
--basedir=/usr/local/mysql: 安裝目錄
--datadir=/usr/local/mysql/mysql-files: 數據存放目錄
--lower_case_table_names=1: 不區分大小寫(這個根據本身需求來,能夠先搜索看看)
注: 該命令運行後, 會產生一個臨時登陸密碼, 在返回結果的最後一行(可搜索看看)
10.添加mysql服務到系統,並完成受權
(1) cd /usr/local/mysql
(2) cp -a ./support-files/mysql.server /etc/init.d/mysql
(3) chmod +x /etc/init.d/mysql
(4) chkconfig --add mysql
mysql啓動: service mysql start
mysql狀態查看: service mysql status
mysql登陸
(1) mysql -uroot -p
(2) 須要輸入的密碼是 第9步中運行生成基礎數據後, 返回結果中給出的臨時密碼
修改密碼
(1) ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql'; (xxxx - 這裏須要本身設置密碼)
(2) flush privileges; (密碼生效)
容許遠程鏈接 use mysql
(1) update user set host='%' where user='root'; (root表示想要被鏈接的數據庫的用戶名,其中「%」表示容許全部機器能訪問root用戶.若是失敗的話,有多是由於數據庫的用戶名不是root,這種狀況下,只須要將root改成數據庫用戶名就能夠了。)
(2) flush privileges;
16.修改 server_id系統變量
主庫
set global server_id=1151;
從庫1
set global server_id=1152;
從庫2
set global server_id=1153;
mysql> show master status;
+---------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000003 | 438 | | | |
+---------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql>
--主庫
create USER 'repl'@'localhost' IDENTIFIED WITH mysql_native_password BY 'mysql';
[root@mysql01 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 26
Server version: 8.0.22 MySQL Community Server - GPL
Copyright (c) 2000, 2020, 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> grant replication slave,replication client on . to 'repl'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
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> update user set host='%' where user='repl';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> grant replication slave,replication client on . to 'repl'@'%';
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant replication slave,replication client on . to 'repl'@'%';
Query OK, 0 rows affected (0.00 sec)
mysql>
19.在從庫上建立主庫的信息
change master to
master_host='10.10.10.151',
master_port=3306,
master_user='repl',
master_password='mysql',
master_log_file='binlog.000003',
master_log_pos=438;
20 在從庫啓動複製查看複製進程
start slave;
show slave status\G
mysql> show slave status\G
1. row
Slave_IO_State: Waiting for master to send event
Master_Host: 10.10.10.151
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000003
Read_Master_Log_Pos: 1860
Relay_Log_File: mysql03-relay-bin.000002
Relay_Log_Pos: 1743
Relay_Master_Log_File: binlog.000003
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1860
Relay_Log_Space: 1954
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1151
Master_UUID: aa703403-34ba-11eb-a6f8-000c295ce2e2
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
mysql> select * from mysql.user where user='repl'\G
1. row
Host: %
User: repl
Select_priv: N
Insert_priv: N
Update_priv: N
Delete_priv: N
Create_priv: N
Drop_priv: N
Reload_priv: N
Shutdown_priv: N
Process_priv: N
File_priv: N
Grant_priv: N
References_priv: N
Index_priv: N
Alter_priv: N
Show_db_priv: N
Super_priv: N
Create_tmp_table_priv: N
Lock_tables_priv: N
Execute_priv: N
Repl_slave_priv: Y
Repl_client_priv: Y
Create_view_priv: N
Show_view_priv: N
Create_routine_priv: N
Alter_routine_priv: N
Create_user_priv: N
Event_priv: N
Trigger_priv: N
Create_tablespace_priv: N
ssl_type:
ssl_cipher: 0x
x509_issuer: 0x
x509_subject: 0x
max_questions: 0
max_updates: 0
max_connections: 0
max_user_connections: 0
plugin: mysql_native_password
authentication_string: *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA
password_expired: N
password_last_changed: 2020-12-03 01:07:52
password_lifetime: NULL
account_locked: N
Create_role_priv: N
Drop_role_priv: N
Password_reuse_history: NULL
Password_reuse_time: NULL
Password_require_current: NULL
User_attributes: NULL
1 row in set (0.01 sec)
mysql>
報錯處理從庫上出現故障 unblock with 'mysqladmin flush-hosts'報錯
mysql> show slave status\G
1. row
Slave_IO_State: Connecting to master
Master_Host: 10.10.10.151
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000003
Read_Master_Log_Pos: 438
Relay_Log_File: mysql02-relay-bin.000002
Relay_Log_Pos: 4
Relay_Master_Log_File: binlog.000003
Slave_IO_Running: Connecting
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 125
Relay_Log_Space: 156
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 1129
Last_IO_Error: error connecting to master 'repl@10.10.10.151:3306' - retry-time: 60 retries: 5 message: Host '10.10.10.152' is blocked because of many connection errors;
unblock with 'mysqladmin flush-hosts'
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_UUID:
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp: 201203 01:51:49
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.00 sec)
出現這個報錯:
unblock with 'mysqladmin flush-hosts'
解決方法1:修改max_connect_errors的值
(1)進入Mysql數據庫查看max_connect_errors:
show variables like '%max_connect_errors%';
(2)修改max_connect_errors的值:
set global max_connect_errors = 100;
(3)查看是否修改爲功
show variables like '%max_connect_errors%';
解決方法2:使用mysqladmin flush-hosts 命令清理一下hosts文件
(1)在查找到的目錄下使用命令修改:mysqladmin -u xxx -p flush-hosts
或者
flush hosts;
解決方法3:重啓mysqld
也能夠在重啓以前,在配置文件中將該參數調大。
max_connect_errors = 100