Mysql主從數據庫搭建流程html
新手開始學習mysql主從庫,遇到一些問題,總結後寫出如下流程mysql
下面以5.7.23版本爲例介紹sql
第一步:去官網下載5.7.23版本的免安裝壓縮包形式的mysql文件,貼上網址吧:https://dev.mysql.com/downloads/mysql/5.7.html#downloads
第二步:將下載好解壓後的mysql文件放到D盤任何一非中文目錄下(不是必須,避免出問題),並在mysql文件後面標註序號1和序號2數據庫
第三步:在mysql文件的根目錄下新建一個my.ini文件,將文件拷貝進去ide
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# 如下內容手動添加
[client]
port=3307
default-character-set=utf8
[mysqld]
#主庫配置
#skip_grant_tables
server_id=1
log_bin=master-bin
log_bin-index=master-bin.index
#端口
port=3306
character_set_server=utf8
#解壓目錄
basedir = D:\Software\Mysql\mysql-5.7.23-winx64-1
#解壓目錄下data目錄
datadir = D:\Software\Mysql\mysql-5.7.23-winx64-1\data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[WinMySQLAdmin]
D:\Software\Mysql\mysql-5.7.23-winx64-1\bin\mysqld.exe
第四步:管理員方式打開CMD,進入mysql的bin目錄下,執行如下語句,紅色的路徑記得改爲本身的噢
mysqld --install slave --defaults-file="D:\software\Mysql\mysql-5.7.23-winx64-2\my.ini"
第五步:執行mysqld --initialize-insecure --user=root ,這句命令是爲了初始化數據庫data
第六步:執行命令 net start mysql啓動服務工具
到此,mysql數據庫配置成功學習
接下來,開始修改mysql的權限和修改root的密碼(前提是服務必需要打開噢)
第一步:輸入命令myslq -h localhost -P 3306 -u root 進入mysql數據庫(當時爲了解決這個問題浪費了不少時間,仍是由於對mysql不熟的緣由)
後面依次輸入如下命令便可ui
mysql>use mysql;spa
mysql>update user set host='%' where user='root';3d
mysql>flush privileges;
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql>ALTER USER 'root'@'%' IDENTIFIED BY '123456';
mysql>exit;
到這裏,你的mysql主庫已經配置成功了,能夠下載一個SQLyog等工具訪問你的數據庫吧
從庫的安裝流程參考主庫安裝流程,只是my.ini文件稍有不一樣,下面是從庫的my.ini文件
從庫安裝完成後,至此主從庫已經安裝完成了
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.
[mysqld]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set, remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
# 如下內容手動添加
[client]
port=3307
default-character-set=utf8
[mysqld]
#從庫配置
server_id=2
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
#端口
port=3307
character_set_server=utf8
#解壓目錄
basedir=G:\Mysql\mysql-5.6.38-winx64
#解壓目錄下data目錄
datadir=G:\Mysql\mysql-5.6.38-winx64\data
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[WinMySQLAdmin]
G:\Mysql\mysql-5.6.38-winx64\bin\mysqld.exe
my.ini
剩下的配置就再也不贅述了,請參考https://www.cnblogs.com/naruto123/p/8138708.html
感謝大神們無私分享經驗,
以上分享只是我在使用5.7.23版本搭建主從庫時參考了5.6的主從庫教程,搭建時出現了問題因此才總結出一篇
參考大神的經驗時必定要有本身的思考和總結